
package{

	import flash.display.*;
	import flash.events.*;

	[SWF(width="640",height="480")]
	
	public class MonkeyGame extends Sprite{
	
		public function MonkeyGame(){
		
			addEventListener( Event.ADDED_TO_STAGE,OnAddedToStage );
		}
		
		private function OnAddedToStage( e:Event ):void{
		
			BBMonkeyGame.Main( this );
		}
	}
}

final class Config{
//${CONFIG_BEGIN}
internal static var BINARY_FILES:String="|*.obj|*.b3d|*.mtl"
internal static var BRL_DATABUFFER_IMPLEMENTED:String="1"
internal static var BRL_GAMETARGET_IMPLEMENTED:String="1"
internal static var BRL_HTTPREQUEST_IMPLEMENTED:String="1"
internal static var BRL_THREAD_IMPLEMENTED:String="1"
internal static var CONFIG:String="release"
internal static var FLASH_RENDER_WHILE_SUSPENDED:String="0"
internal static var HOST:String="winnt"
internal static var IMAGE_FILES:String="*.png|*.jpg"
internal static var LANG:String="as"
internal static var MINIB3D_DEBUG_MODEL:String="0"
internal static var MINIB3D_DRIVER:String=""
internal static var MOJO_AUTO_SUSPEND_ENABLED:String="1"
internal static var MOJO_DRIVER_IMPLEMENTED:String="1"
internal static var MOJO_IMAGE_FILTERING_ENABLED:String="1"
internal static var MUSIC_FILES:String="*.mp3"
internal static var SAFEMODE:String="0"
internal static var SOUND_FILES:String="*.mp3"
internal static var TARGET:String="flash"
internal static var TEXT_FILES:String="*.txt|*.xml|*.xrf|*.xaf|*.xmf|*.xaf|*.xsf"
//${CONFIG_END}
}

final class Assets{
//${ASSETS_BEGIN}
[Embed(source="data/mojo_font.png")]
public static var _9mojo_font3png:Class;
//${ASSETS_END}
}

//${TRANSCODE_BEGIN}

// Actionscript Monkey runtime.
//
// Placed into the public domain 24/02/2011.
// No warranty implied; use at your own risk.

//***** ActionScript Runtime *****

import flash.display.*;
import flash.external.ExternalInterface;

//Consts for radians<->degrees conversions
var D2R:Number=0.017453292519943295;
var R2D:Number=57.29577951308232;

//private
var _errInfo:String="?<?>";
var _errStack:Array=[];

var dbg_index:int=0;

function pushErr():void{
	_errStack.push( _errInfo );
}

function popErr():void{
	_errInfo=_errStack.pop();
}

function stackTrace():String{
	if( !_errInfo.length ) return "";
	var str:String=_errInfo+"\n";
	for( var i:int=_errStack.length-1;i>0;--i ){
		str+=_errStack[i]+"\n";
	}
	return str;
}

function print( str:String ):int{
	try{
		if( ExternalInterface.available ) ExternalInterface.call( "monkey_print",str );
	}catch( ex:Error ){
	}
	return 0;
}

function error( err:String ):int{
	throw err;
}

function debugLog( str:String ):int{
	print( str );
	return 0;
}

function debugStop():int{
	error( "STOP" );
	return 0;
}

function dbg_object( obj:Object ):Object{
	if( obj ) return obj;
	error( "Null object access" );
	return obj;
}

function dbg_array( arr:Array,index:int ):Array{
	if( index<0 || index>=arr.length ) error( "Array index out of range" );
	dbg_index=index;
	return arr;
}

function dbg_charCodeAt( str:String,index:int ):int{
	if( index<0 || index>=str.length ) error( "Character index out of range" );
	return str.charCodeAt( index );
}

function new_bool_array( len:int ):Array{
	var arr:Array=new Array( len )
	for( var i:int=0;i<len;++i ) arr[i]=false;
	return arr;
}

function new_number_array( len:int ):Array{
	var arr:Array=new Array( len )
	for( var i:int=0;i<len;++i ) arr[i]=0;
	return arr;
}

function new_string_array( len:int ):Array{
	var arr:Array=new Array( len );
	for( var i:int=0;i<len;++i ) arr[i]='';
	return arr;
}

function new_array_array( len:int ):Array{
	var arr:Array=new Array( len );
	for( var i:int=0;i<len;++i ) arr[i]=[];
	return arr;
}

function new_object_array( len:int ):Array{
	var arr:Array=new Array( len );
	for( var i:int=0;i<len;++i ) arr[i]=null;
	return arr;
}

function resize_bool_array( arr:Array,len:int ):Array{
	var i:int=arr.length;
	arr=arr.slice(0,len);
	if( len<=i ) return arr;
	arr.length=len;
	while( i<len ) arr[i++]=false;
	return arr;
}

function resize_number_array( arr:Array,len:int ):Array{
	var i:int=arr.length;
	arr=arr.slice(0,len);
	if( len<=i ) return arr;
	arr.length=len;
	while( i<len ) arr[i++]=0;
	return arr;
}

function resize_string_array( arr:Array,len:int ):Array{
	var i:int=arr.length;
	arr=arr.slice(0,len);
	if( len<=i ) return arr;
	arr.length=len;
	while( i<len ) arr[i++]="";
	return arr;
}

function resize_array_array( arr:Array,len:int ):Array{
	var i:int=arr.length;
	arr=arr.slice(0,len);
	if( len<=i ) return arr;
	arr.length=len;
	while( i<len ) arr[i++]=[];
	return arr;
}

function resize_object_array( arr:Array,len:int ):Array{
	var i:int=arr.length;
	arr=arr.slice(0,len);
	if( len<=i ) return arr;
	arr.length=len;
	while( i<len ) arr[i++]=null;
	return arr;
}

function string_compare( lhs:String,rhs:String ):int{
	var n:int=Math.min( lhs.length,rhs.length ),i:int,t:int;
	for( i=0;i<n;++i ){
		t=lhs.charCodeAt(i)-rhs.charCodeAt(i);
		if( t ) return t;
	}
	return lhs.length-rhs.length;
}

function string_replace( str:String,find:String,rep:String ):String{	//no unregex replace all?!?
	var i:int=0;
	for(;;){
		i=str.indexOf( find,i );
		if( i==-1 ) return str;
		str=str.substring( 0,i )+rep+str.substring( i+find.length );
		i+=rep.length;
	}
	return str;
}

function string_trim( str:String ):String{
	var i:int=0,i2:int=str.length;
	while( i<i2 && str.charCodeAt(i)<=32 ) i+=1;
	while( i2>i && str.charCodeAt(i2-1)<=32 ) i2-=1;
	return str.slice( i,i2 );
}

function string_tochars( str:String ):Array{
	var arr:Array=new Array( str.length );
	for( var i:int=0;i<str.length;++i ) arr[i]=str.charCodeAt(i);
	return arr;	
}

function string_startswith( str:String,sub:String ):Boolean{
	return sub.length<=str.length && str.slice(0,sub.length)==sub;
}

function string_endswith( str:String,sub:String ):Boolean{
	return sub.length<=str.length && str.slice(str.length-sub.length,str.length)==sub;
}

function string_fromchars( chars:Array ):String{
	var str:String="",i:int;
	for( i=0;i<chars.length;++i ){
		str+=String.fromCharCode( chars[i] );
	}
	return str;
}

class ThrowableObject{
	internal function toString():String{
		return "Uncaught Monkey Exception";
	}
}


import flash.display.*;
import flash.events.*;
import flash.media.*;
import flash.net.*;
import flash.utils.ByteArray;

import flash.ui.*;

class BBGameEvent{
	public static const KeyDown:int=1;
	public static const KeyUp:int=2;
	public static const KeyChar:int=3;
	public static const MouseDown:int=4;
	public static const MouseUp:int=5;
	public static const MouseMove:int=6;
	public static const TouchDown:int=7;
	public static const TouchUp:int=8;
	public static const TouchMove:int=9;
	public static const MotionAccel:int=10;
}

class BBGameDelegate{
	public function StartGame():void{}
	public function SuspendGame():void{}
	public function ResumeGame():void{}
	public function UpdateGame():void{}
	public function RenderGame():void{}
	public function KeyEvent( event:int,data:int ):void{}
	public function MouseEvent( event:int,data:int,x:Number,y:Number ):void{}
	public function TouchEvent( event:int,data:int,x:Number,y:Number ):void{}
	public function MotionEvent( event:int,data:int,x:Number,y:Number,z:Number ):void{}
	public function DiscardGraphics():void{}
}

class BBDisplayMode{
	public var width:int;
	public var height:int;
}

class BBGame{

	internal static var _game:BBGame;

	internal var _delegate:BBGameDelegate;
	internal var _keyboardEnabled:Boolean;
	internal var _updateRate:int;
	internal var _debugExs:Boolean;
	internal var _started:Boolean;
	internal var _suspended:Boolean;
	internal var _startms:Number;
	
	public function BBGame(){
		_game=this;
		_debugExs=(Config.CONFIG=="debug");
		_startms=(new Date).getTime();
	}
	
	public static function Game():BBGame{
		return _game;
	}
	
	public function SetDelegate( delegate:BBGameDelegate ):void{
		_delegate=delegate;
	}
	
	public function Delegate():BBGameDelegate{
		return _delegate;
	}
	
	public function SetKeyboardEnabled( enabled:Boolean ):void{
		_keyboardEnabled=enabled;
	}
	
	public function SetUpdateRate( hertz:int ):void{
		_updateRate=hertz;
	}
	
	public function Started():Boolean{
		return _started;
	}
	
	public function Suspended():Boolean{
		return _suspended;
	}
	
	public function Millisecs():int{
		return (new Date).getTime()-_startms;
	}
	
	public function GetDate( date:Array ):void{
		var n:int=date.length;
		if( n>0 ){
			var t:Date=new Date();
			date[0]=t.getFullYear();
			if( n>1 ){
				date[1]=t.getMonth()+1;
				if( n>2 ){
					date[2]=t.getDate();
					if( n>3 ){
						date[3]=t.getHours();
						if( n>4 ){
							date[4]=t.getMinutes();
							if( n>5 ){
								date[5]=t.getSeconds();
								if( n>6 ){
									date[6]=t.getMilliseconds();
								}
							}
						}
					}
				}
			}
		}
	}
	
	public function SaveState( state:String ):int{
		var file:SharedObject=SharedObject.getLocal( "monkeystate" );
		file.data.state=state;
		file.close();
		return 0;
	}
	
	public function LoadState():String{
		var file:SharedObject=SharedObject.getLocal( "monkeystate" );
		var state:String=file.data.state;
		file.close();
		if( state ) return state;
		return "";
	}

	public function LoadString( path:String ):String{
		var buf:ByteArray=LoadData( path );
		if( buf ) return buf.toString();
		return "";
	}
	
	public function PollJoystick( port:int,joyx:Array,joyy:Array,joyz:Array,buttons:Array ):Boolean{
		return false;
	}
	
	public function OpenUrl( url:String ):void{
		navigateToURL( new URLRequest( url ) );
	}
	
	public function SetMouseVisible( visible:Boolean ):void{
		if( visible ){
			Mouse.show();
		}else{
			Mouse.hide();
		}
	}
	
	public function GetDeviceWidth():int{
		return 0;
	}
	
	public function GetDeviceHeight():int{
		return 0;
	}
	
	public function SetDeviceWindow( width:int,height:int,flags:int ):void{
	}
	
	public function GetDisplayModes():Array{
		return new Array();
	}
	
	public function GetDesktopMode():BBDisplayMode{
		return null;
	}
	
	public function SetSwapInterval( interval:int ):void{
	}
	
	public function PathToFilePath( path:String ):String{
		return "";
	}
	
	//***** Flash Game *****
	
	public function PathToUrl( path:String ):String{
		return path;
	}
	
	public function LoadData( path:String ):ByteArray{
		//TODO: Load from URL
		return null;
	}
	
	//***** INTERNAL *****
	public function Die( ex:Object ):void{
	
		_delegate=new BBGameDelegate();
		
		if( !ex.toString() ){
			return;
		}
		if( _debugExs ){
			print( "Monkey Runtime Error : "+ex.toString() );
			print( stackTrace() );
		}
		throw ex;
	}
	
	public function StartGame():void{
	
		if( _started ) return;
		_started=true;
		
		try{
			_delegate.StartGame();
		}catch( ex:Object ){
			Die( ex );
		}
	}
	
	public function SuspendGame():void{
	
		if( !_started || _suspended ) return;
		_suspended=true;
		
		try{
			_delegate.SuspendGame();
		}catch( ex:Object ){
			Die( ex );
		}
	}
	
	public function ResumeGame():void{

		if( !_started || !_suspended ) return;
		_suspended=false;
		
		try{
			_delegate.ResumeGame();
		}catch( ex:Object ){
			Die( ex );
		}
	}
	
	public function UpdateGame():void{

		if( !_started || _suspended ) return;
		
		try{
			_delegate.UpdateGame();
		}catch( ex:Object ){
			Die( ex );
		}
	}
	
	public function RenderGame():void{

		if( !_started ) return;
		
		try{
			_delegate.RenderGame();
		}catch( ex:Object ){
			Die( ex );
		}
	}
	
	public function KeyEvent( ev:int,data:int ):void{

		if( !_started ) return;
		
		try{
			_delegate.KeyEvent( ev,data );
		}catch( ex:Object ){
			Die( ex );
		}
	}
	
	public function MouseEvent( ev:int,data:int,x:Number,y:Number ):void{

		if( !_started ) return;
		
		try{
			_delegate.MouseEvent( ev,data,x,y );
		}catch( ex:Object ){
			Die( ex );
		}
	}
	
	public function TouchEvent( ev:int,data:int,x:Number,y:Number ):void{

		if( !_started ) return;
		
		try{
			_delegate.TouchEvent( ev,data,x,y );
		}catch( ex:Object ){
			Die( ex );
		}
	}
	
	public function MotionEvent( ev:int,data:int,x:Number,y:Number,z:Number ):void{

		if( !_started ) return;
		
		try{
			_delegate.MotionEvent( ev,data,x,y,z );
		}catch( ex:Object ){
			Die( ex );
		}
	}
	
	public function DiscardGraphics():void{

		if( !_started ) return;
		
		try{
			_delegate.DiscardGraphics();
		}catch( ex:Object ){
			Die( ex );
		}
	}
}


class BBFlashGame extends BBGame{

	internal static var _flashGame:BBFlashGame;
	
	internal var _root:DisplayObjectContainer;
	
	internal var _nextUpdate:Number;
	internal var _updatePeriod:Number;

	public function BBFlashGame( root:DisplayObjectContainer ){
		_flashGame=this;
		_root=root;
	}
	
	public static function FlashGame():BBFlashGame{
		return _flashGame;
	}
	
	internal function KeyToChar( key:int ):int{
		switch( key ){
		case 8:case 9:case 13:case 27:return key;
		case 33:case 34:case 35:case 36:case 37:case 38:case 39:case 40:case 45:return key | 0x10000;
		case 46:return 127;
		}
		return 0;
	}
	
	internal function ValidateUpdateTimer():void{
		if( _suspended ){
			_root.stage.frameRate=24;
		}else if( _updateRate ){
			_updatePeriod=1000.0/_updateRate;
			_nextUpdate=0;
			_root.stage.frameRate=_updateRate;
		}else{
			_root.stage.frameRate=60;
		}
	}
	
	//***** BBGame *****	
	
	public override function GetDeviceWidth():int{
		return _root.stage.stageWidth;
	}
	
	public override function GetDeviceHeight():int{
		return _root.stage.stageHeight;
	}
	
	public override function SetUpdateRate( hertz:int ):void{
		super.SetUpdateRate( hertz );
		ValidateUpdateTimer();
	}
	
	public override function PathToUrl( path:String ):String {
		if( path.indexOf( "monkey:" )!=0 ){
			return path;
		}else if( path.indexOf( "monkey://data/" )==0 ){
			return "data/"+path.slice( 14 );
		}
		return "";
	}

	public override function LoadData( path:String ):ByteArray{
		var t:Class=GetAsset( path );
		if( t ) return (new t) as ByteArray;
		return null;
	}

	public function GetDisplayObjectContainer():DisplayObjectContainer{
		return _root;
	}

	public function GetAsset( path:String ):Class{
		if( path.indexOf( "monkey://data/" )!=0 ) return null;

		path=path.slice(14);
		
		var i:int=path.indexOf( "." ),ext:String="";
		if( i!=-1 ){
			ext=path.slice(i+1);
			path=path.slice(0,i);
		}

		var munged:String="_";
		var bits:Array=path.split( "/" );
		
		for( i=0;i<bits.length;++i ){
			munged+=bits[i].length+bits[i];
		}
		munged+=ext.length+ext;
		
		return Assets[munged];
	}
	
	public function LoadBitmap( path:String ):Bitmap{
		var t:Class=GetAsset( path );
		if( t ) return (new t) as Bitmap;
		return null;
	}
	
	public function LoadSound( path:String ):Sound{
		var t:Class=GetAsset( path );
		if( t ) return (new t) as Sound;
		return null;
	}
	
	//***** INTERNAL *****
	
	public override function SuspendGame():void{
		super.SuspendGame();
		super.RenderGame();
		ValidateUpdateTimer();
	}
	
	public override function ResumeGame():void{
		super.ResumeGame();
		ValidateUpdateTimer();
	}

	public function Run():void{

		_root.stage.addEventListener( Event.ACTIVATE,OnActivate );
		_root.stage.addEventListener( Event.DEACTIVATE,OnDeactivate );
		_root.stage.addEventListener( Event.ENTER_FRAME,OnEnterFrame );
		_root.stage.addEventListener( KeyboardEvent.KEY_DOWN,OnKeyDown );
		_root.stage.addEventListener( KeyboardEvent.KEY_UP,OnKeyUp );
		_root.stage.addEventListener( flash.events.MouseEvent.MOUSE_DOWN,OnMouseDown );
		_root.stage.addEventListener( flash.events.MouseEvent.MOUSE_UP,OnMouseUp );
		_root.stage.addEventListener( flash.events.MouseEvent.MOUSE_MOVE,OnMouseMove );
		
		StartGame();
	}

	public function OnActivate( e:Event ):void{
		if( Config.MOJO_AUTO_SUSPEND_ENABLED=="1" ) ResumeGame();
	}
	
	public function OnDeactivate( e:Event ):void{
		if( Config.MOJO_AUTO_SUSPEND_ENABLED=="1" ) SuspendGame();
	}
	
	public function OnEnterFrame( e:Event ):void{
		if( _suspended ){
			if( Config.FLASH_RENDER_WHILE_SUSPENDED=="1" ) RenderGame();
			return;
		}
		
		if( !_updateRate ){
			UpdateGame();
			RenderGame();
			return;
		}
		
		if( !_nextUpdate ) _nextUpdate=(new Date).getTime();
		
		var i:int;
		for( i=0;i<4;++i ){
		
			UpdateGame();
			if( !_nextUpdate ) break;
			
			_nextUpdate+=_updatePeriod;
			if( (new Date).getTime()<_nextUpdate ) break;
		}
		if( i==4 ) _nextUpdate=0;
		RenderGame();
	}
	
	public function OnKeyDown( e:KeyboardEvent ):void{
		KeyEvent( BBGameEvent.KeyDown,e.keyCode );
		if( e.charCode!=0 ){
			KeyEvent( BBGameEvent.KeyChar,e.charCode );
		}else{
			var chr:int=KeyToChar( e.keyCode );
			if( chr ) KeyEvent( BBGameEvent.KeyChar,chr );
		}
	}

	public function OnKeyUp( e:KeyboardEvent ):void{
		KeyEvent( BBGameEvent.KeyUp,e.keyCode );
	}
		
	public function OnMouseDown( e:flash.events.MouseEvent ):void{
		MouseEvent( BBGameEvent.MouseDown,0,e.localX,e.localY );
	}
		
	public function OnMouseUp( e:flash.events.MouseEvent ):void{
		MouseEvent( BBGameEvent.MouseUp,0,e.localX,e.localY );
	}

	public function OnMouseMove( e:flash.events.MouseEvent ):void{
		MouseEvent( BBGameEvent.MouseMove,-1,e.localX,e.localY );
	}

}


class BBMonkeyGame extends BBFlashGame{

	internal static var _monkeyGame:BBMonkeyGame;
	
	public function BBMonkeyGame( root:DisplayObjectContainer ){
		super( root );
	}
	
	public static function Main( root:DisplayObjectContainer ):void{
		
		_monkeyGame=new BBMonkeyGame( root );

		try{
		
			bbInit();
			bbMain();
			
		}catch( ex:Object ){
		
			_monkeyGame.Die( ex );
			return;
		}
		
		if( !_monkeyGame.Delegate() ) return;
		
		_monkeyGame.Run();
	}
}


// Flash mojo runtime.
//
// Copyright 2011 Mark Sibly, all rights reserved.
// No warranty implied; use at your own risk.

import flash.display.*;
import flash.events.*;
import flash.media.*;
import flash.geom.*;
import flash.utils.*;
import flash.net.*;

class gxtkGraphics{

	internal var game:BBFlashGame;
	internal var stage:Stage;

	internal var bitmap:Bitmap;
	
	internal var red:Number=255;
	internal var green:Number=255;
	internal var blue:Number=255;
	internal var alpha:Number=1;
	internal var colorARGB:uint=0xffffffff;
	internal var colorTform:ColorTransform=null;
	internal var alphaTform:ColorTransform=null;
	
	internal var matrix:Matrix;
	internal var rectBMData:BitmapData;
	internal var blend:String;
	internal var clipRect:Rectangle;
	
	internal var shape:Shape;
	internal var graphics:Graphics;
	internal var bitmapData:BitmapData;
	
	internal var graphics_dirty:Boolean;

	internal var pointMat:Matrix=new Matrix;
	internal var rectMat:Matrix=new Matrix;
	internal var imageMat:Matrix=new Matrix;
	internal var pointCoords:Point=new Point;
	
	internal var image_filtering_enabled:Boolean;
	
	function gxtkGraphics(){

		game=BBFlashGame.FlashGame();
		stage=game.GetDisplayObjectContainer().stage;
		
		image_filtering_enabled=(Config.MOJO_IMAGE_FILTERING_ENABLED=="1");
		
		bitmap=new Bitmap();
		bitmap.bitmapData=new BitmapData( stage.stageWidth,stage.stageHeight,false,0xff0000ff );
		bitmap.smoothing=image_filtering_enabled;
		bitmap.width=stage.stageWidth;
		bitmap.height=stage.stageHeight;
		
		game.GetDisplayObjectContainer().addChild( bitmap );

		shape=new Shape;
		graphics=shape.graphics;
		bitmapData=bitmap.bitmapData;
	
		stage.addEventListener( Event.RESIZE,OnResize );
	
		rectBMData=new BitmapData( 1,1,false,0xffffffff );
		
		image_filtering_enabled=(Config.MOJO_IMAGE_FILTERING_ENABLED=="1");
	}
	
	internal function OnResize( e:Event ):void{
		var w:int=stage.stageWidth;
		var h:int=stage.stageHeight;
		if( w==bitmap.width && h==bitmap.height ) return;
		bitmap.bitmapData=new BitmapData( w,h,false,0xff0000ff );
		bitmap.width=w;
		bitmap.height=h;
	}

	internal function BeginRender():int{
		return 1;
	}

	internal function UseGraphics():void{
		if( graphics_dirty && alphaTform ){
			bitmapData.draw( shape,matrix,alphaTform,blend,clipRect,false );
			graphics.clear();
			return;
		}
		graphics_dirty=true;
	}

	internal function FlushGraphics():void{
		if( graphics_dirty ){
			graphics_dirty=false;
			bitmapData.draw( shape,matrix,alphaTform,blend,clipRect,false );
			graphics.clear();
		}
	}
	
	internal function EndRender():void{
		FlushGraphics();
	}
	
	internal function DiscardGraphics():void{
	}
	
	internal function updateColor():void{
	
		colorARGB=(int(alpha*255)<<24)|(int(red)<<16)|(int(green)<<8)|int(blue);
		
		if( colorARGB==0xffffffff ){
			colorTform=null;
			alphaTform=null;
		}else{
			colorTform=new ColorTransform( red/255.0,green/255.0,blue/255.0,alpha );
			if( alpha==1 ){
				alphaTform=null;
			}else{
				alphaTform=new ColorTransform( 1,1,1,alpha );
			}
		}
	}

	//***** GXTK API *****

	public function Width():int{
		return bitmap.width;
	}

	public function Height():int{
		return bitmap.height;
	}
	
	public function LoadSurface__UNSAFE__( surface:gxtkSurface,path:String ):gxtkSurface{
		return null;
	}

	public function LoadSurface( path:String ):gxtkSurface{
		var bitmap:Bitmap=game.LoadBitmap( path );
		if( bitmap==null ) return null;
		return new gxtkSurface( bitmap );
	}
	
	public function CreateSurface( width:int,height:int ):gxtkSurface{
		var bitmapData:BitmapData=new BitmapData( width,height,true,0 );
		var bitmap:Bitmap=new Bitmap( bitmapData );
		return new gxtkSurface( bitmap );
	}
	
	public function SetAlpha( a:Number ):int{
		FlushGraphics();
		
		alpha=a;
		
		updateColor();
		
		return 0;
	}
	
	public function SetColor( r:Number,g:Number,b:Number ):int{
		FlushGraphics();
		
		red=r;
		green=g;
		blue=b;
		
		updateColor();
		
		return 0;
	}
	
	public function SetBlend( blend:int ):int{
		switch( blend ){
		case 1:
			this.blend=BlendMode.ADD;
			break;
		default:
			this.blend=null;
		}
		return 0;
	}
	
	public function SetScissor( x:int,y:int,w:int,h:int ):int{
		FlushGraphics();
		
		if( x!=0 || y!=0 || w!=bitmap.width || h!=bitmap.height ){
			clipRect=new Rectangle( x,y,w,h );
		}else{
			clipRect=null;
		}
		return 0;
	}

	public function SetMatrix( ix:Number,iy:Number,jx:Number,jy:Number,tx:Number,ty:Number ):int{
		FlushGraphics();
		
		if( ix!=1 || iy!=0 || jx!=0 || jy!=1 || tx!=0 || ty!=0 ){
			matrix=new Matrix( ix,iy,jx,jy,tx,ty );
		}else{
			matrix=null;
		}
		return 0;
	}

	public function Cls( r:Number,g:Number,b:Number ):int{
		FlushGraphics();

		var clsColor:uint=0xff000000|(int(r)<<16)|(int(g)<<8)|int(b);
		var rect:Rectangle=clipRect;
		if( !rect ) rect=new Rectangle( 0,0,bitmap.width,bitmap.height );
		bitmapData.fillRect( rect,clsColor );
		return 0;
	}
	
	public function DrawPoint( x:Number,y:Number ):int{
		FlushGraphics();
		
		if( matrix ){
			var px:Number=x;
			x=px * matrix.a + y * matrix.c + matrix.tx;
			y=px * matrix.b + y * matrix.d + matrix.ty;
		}
		if( clipRect || alphaTform || blend ){
			pointMat.tx=x;pointMat.ty=y;
			bitmapData.draw( rectBMData,pointMat,colorTform,blend,clipRect,false );
		}else{
			bitmapData.fillRect( new Rectangle( x,y,1,1 ),colorARGB );
		}
		return 0;
	}
	
	
	public function DrawRect( x:Number,y:Number,w:Number,h:Number ):int{
		FlushGraphics();
		
		if( matrix ){
			var mat:Matrix=new Matrix( w,0,0,h,x,y );
			mat.concat( matrix );
			bitmapData.draw( rectBMData,mat,colorTform,blend,clipRect,false );
		}else if( clipRect || alphaTform || blend ){
			rectMat.a=w;rectMat.d=h;rectMat.tx=x;rectMat.ty=y;
			bitmapData.draw( rectBMData,rectMat,colorTform,blend,clipRect,false );
		}else{
			bitmapData.fillRect( new Rectangle( x,y,w,h ),colorARGB );
		}
		return 0;
	}

	public function DrawLine( x1:Number,y1:Number,x2:Number,y2:Number ):int{
		
		if( matrix ){
		
			FlushGraphics();
			
			var x1_t:Number=x1 * matrix.a + y1 * matrix.c + matrix.tx;
			var y1_t:Number=x1 * matrix.b + y1 * matrix.d + matrix.ty;
			var x2_t:Number=x2 * matrix.a + y2 * matrix.c + matrix.tx;
			var y2_t:Number=x2 * matrix.b + y2 * matrix.d + matrix.ty;
			
			graphics.lineStyle( 1,colorARGB & 0xffffff );	//why the mask?
			graphics.moveTo( x1_t,y1_t );
			graphics.lineTo( x2_t,y2_t );
			graphics.lineStyle();
			
			bitmapData.draw( shape,null,alphaTform,blend,clipRect,false );
			graphics.clear();
			
		}else{
		
			UseGraphics();

			graphics.lineStyle( 1,colorARGB & 0xffffff );	//why the mask?
			graphics.moveTo( x1,y1 );
			graphics.lineTo( x2,y2 );
			graphics.lineStyle();
		}

		return 0;
 	}

	public function DrawOval( x:Number,y:Number,w:Number,h:Number ):int{
		UseGraphics();

		graphics.beginFill( colorARGB & 0xffffff );			//why the mask?
		graphics.drawEllipse( x,y,w,h );
		graphics.endFill();

		return 0;
	}
	
	public function DrawPoly( verts:Array ):int{
		if( verts.length<2 ) return 0;
		
		UseGraphics();
		
		graphics.beginFill( colorARGB & 0xffffff );			//why the mask?
		
		graphics.moveTo( verts[0],verts[1] );
		for( var i:int=2;i<verts.length;i+=2 ){
			graphics.lineTo( verts[i],verts[i+1] );
		}
		graphics.endFill();
		
		return 0;
	}

	public function DrawPoly2( verts:Array,surface:gxtkSurface,srcx:int,srcy:int ):int{
		if( verts.length<4 ) return 0;
		
		UseGraphics();
		
		graphics.beginFill( colorARGB & 0xffffff );			//why the mask?
		
		graphics.moveTo( verts[0],verts[1] );
		for( var i:int=4;i<verts.length;i+=4 ){
			graphics.lineTo( verts[i],verts[i+1] );
		}
		graphics.endFill();
		
		return 0;
	}

	public function DrawSurface( surface:gxtkSurface,x:Number,y:Number ):int{
		FlushGraphics();
		
		if( matrix ){
			var mat:Matrix=new Matrix( 1,0,0,1,x,y );
			mat.concat( matrix );
			bitmapData.draw( surface.bitmap.bitmapData,mat,colorTform,blend,clipRect,image_filtering_enabled );
		}else if( clipRect || colorTform || blend ){
			imageMat.tx=x;imageMat.ty=y;
			bitmapData.draw( surface.bitmap.bitmapData,imageMat,colorTform,blend,clipRect,image_filtering_enabled );
		}else{
			pointCoords.x=x;pointCoords.y=y;
			bitmapData.copyPixels( surface.bitmap.bitmapData,surface.rect,pointCoords );
		}

		return 0;
	}

	public function DrawSurface2( surface:gxtkSurface,x:Number,y:Number,srcx:int,srcy:int,srcw:int,srch:int ):int{
		if( srcw<0 ){ srcx+=srcw;srcw=-srcw; }
		if( srch<0 ){ srcy+=srch;srch=-srch; }
		if( srcw<=0 || srch<=0 ) return 0;
		
		FlushGraphics();

		var srcrect:Rectangle=new Rectangle( srcx,srcy,srcw,srch );
		
		if( matrix || clipRect || colorTform || blend ){

			var scratch:BitmapData=surface.scratch;
			if( scratch==null || srcw!=scratch.width || srch!=scratch.height ){
				if( scratch!=null ) scratch.dispose();
				scratch=new BitmapData( srcw,srch );
				surface.scratch=scratch;
			}
			pointCoords.x=0;pointCoords.y=0;
			scratch.copyPixels( surface.bitmap.bitmapData,srcrect,pointCoords );
			
			var mat:Matrix;
			if( matrix ){
				mat=new Matrix( 1,0,0,1,x,y );
				mat.concat( matrix );
			}else{
				imageMat.tx=x;imageMat.ty=y;
				mat=imageMat;
			}
			bitmapData.draw( scratch,mat,colorTform,blend,clipRect,image_filtering_enabled );
		}else{
			pointCoords.x=x;pointCoords.y=y;
			bitmapData.copyPixels( surface.bitmap.bitmapData,srcrect,pointCoords );
		}
		return 0;
	}
	
	public function ReadPixels( pixels:Array,x:int,y:int,width:int,height:int,offset:int,pitch:int ):int{
	
		FlushGraphics();
		
		var data:ByteArray=bitmapData.getPixels( new Rectangle( x,y,width,height ) );
		data.position=0;
		
		var px:int,py:int,j:int=offset,argb:int;
		
		for( py=0;py<height;++py ){
			for( px=0;px<width;++px ){
				pixels[j++]=data.readInt();
			}
			j+=pitch-width;
		}
		
		return 0;
	}
	
	public function WritePixels2( surface:gxtkSurface,pixels:Array,x:int,y:int,width:int,height:int,offset:int,pitch:int ):int{

		FlushGraphics();
		
		var data:ByteArray=new ByteArray();
		data.length=width*height;
			
		var px:int,py:int,j:int=offset,argb:int;
		
		for( py=0;py<height;++py ){
			for( px=0;px<width;++px ){
				data.writeInt( pixels[j++] );
			}
			j+=pitch-width;
		}
		data.position=0;
		
		surface.bitmap.bitmapData.setPixels( new Rectangle( x,y,width,height ),data );
		
		return 0;
	}
}

//***** gxtkSurface *****

class gxtkSurface{
	internal var bitmap:Bitmap;
	internal var rect:Rectangle;
	internal var scratch:BitmapData;
	
	function gxtkSurface( bitmap:Bitmap ){
		SetBitmap( bitmap );
	}
	
	public function SetBitmap( bitmap:Bitmap ):void{
		this.bitmap=bitmap;
		rect=new Rectangle( 0,0,bitmap.width,bitmap.height );
	}

	//***** GXTK API *****

	public function Discard():int{
		return 0;
	}
	
	public function Width():int{
		return rect.width;
	}

	public function Height():int{
		return rect.height;
	}

	public function Loaded():int{
		return 1;
	}
	
	public function OnUnsafeLoadComplete():Boolean{
		return true;
	}
}

class gxtkChannel{
	internal var channel:SoundChannel;	//null then not playing
	internal var sample:gxtkSample;
	internal var loops:Boolean;
	internal var transform:SoundTransform=new SoundTransform();
	internal var pausepos:Number;
	internal var state:int;				//0=stopped, 1=playing, 2=paused, 5=playing/suspended
}

class gxtkAudio{

	internal var busy:Boolean;

	internal var game:BBFlashGame;
	internal var music:gxtkSample;

	internal var channels:Array=new Array( 33 );

	function gxtkAudio(){
		game=BBFlashGame.FlashGame();
		for( var i:int=0;i<33;++i ){
			channels[i]=new gxtkChannel();
		}
	}
	
	internal function SoundComplete( ev:Event ):void{

		//Should never happen!	
		if( busy ){
			debugLog( "gxtkAudio.SoundComplete Error - audio is busy!" );
			return;
		}
		
		busy=true;
		
		for( var i:int=0;i<33;++i ){
			var chan:gxtkChannel=channels[i];
			if( chan.state==1 && chan.channel==ev.target ){
				if( chan.loops ){
					chan.channel=chan.sample.sound.play( 0,0,chan.transform );
					if( chan.channel ){
						chan.channel.addEventListener( Event.SOUND_COMPLETE,SoundComplete );
						continue;
					}
				}
				chan.channel=null;
				chan.sample=null;
				chan.state=0;
			}
		}
		
		busy=false;
	}
	
	//***** GXTK API *****
	
	public function Suspend():int{
	
		busy=true;
		
		for( var i:int=0;i<33;++i ){
			var chan:gxtkChannel=channels[i];
			if( chan.state==1 ){
				chan.pausepos=chan.channel.position;
				chan.channel.stop();
				chan.channel=null;
				chan.state=5;
			}
		}
		
		busy=false;
		
		return 0;
	}
	
	public function Resume():int{
	
		busy=true;
		
		for( var i:int=0;i<33;++i ){
			var chan:gxtkChannel=channels[i];
			if( chan.state==5 ){
				chan.channel=chan.sample.sound.play( chan.pausepos,0,chan.transform );
				if( chan.channel ){
					chan.channel.addEventListener( Event.SOUND_COMPLETE,SoundComplete );
					chan.state=1;
					continue;
				}
				
				debugLog( "gxtkAudio.Resume() - failed to create SoundChannel" );
				
				chan.sample=null;
				chan.state=0;
			}
		}
		
		busy=false;
		
		return 0;
	}
	
	public function LoadSample__UNSAFE__( sample:gxtkSample,path:String ):gxtkSample{
		return null;
	}
	
	public function LoadSample( path:String ):gxtkSample{
		var sound:Sound=game.LoadSound( path );
		if( sound ) return new gxtkSample( sound );
		return null;
	}
	
	public function PlaySample( sample:gxtkSample,channel:int,flags:int ):int{
		var chan:gxtkChannel=channels[channel];
		
		busy=true;
		
		if( chan.state!=0 ) chan.channel.stop();

		chan.sample=sample;
		chan.loops=(flags & 1)!=0;
		chan.channel=sample.sound.play( 0,0,chan.transform );
		if( chan.channel ){
			chan.channel.addEventListener( Event.SOUND_COMPLETE,SoundComplete );
			chan.state=1;
		}else{
			chan.sample=null;
			chan.state=0;
		}
		
		busy=false;

		return 0;
	}
	
	public function StopChannel( channel:int ):int{
		var chan:gxtkChannel=channels[channel];
		
		busy=true;
		
		if( chan.state!=0 ){
			if( chan.state==1 ){
				chan.channel.stop();
				chan.channel=null;
			}
			chan.sample=null;
			chan.state=0;
		}
		
		busy=false;
		
		return 0;
	}
	
	public function PauseChannel( channel:int ):int{
		var chan:gxtkChannel=channels[channel];
		
		busy=true;
		
		if( chan.state==1 ){
			chan.pausepos=chan.channel.position;
			chan.channel.stop();
			chan.channel=null;
			chan.state=2;
		}
		
		busy=false;
		
		return 0;
	}
	
	public function ResumeChannel( channel:int ):int{
		var chan:gxtkChannel=channels[channel];
		
		busy=true;
		
		if( chan.state==2 ){
			chan.channel=chan.sample.sound.play( chan.pausepos,0,chan.transform );
			if( chan.channel ){
				chan.channel.addEventListener( Event.SOUND_COMPLETE,SoundComplete );
				chan.state=1;
			}else{
				chan.sample=null;
				chan.state=0;
			}
		}
		
		busy=false;
		
		return 0;
	}
	
	public function ChannelState( channel:int ):int{
		var chan:gxtkChannel=channels[channel];
		
		return chan.state & 3;
	}
	
	public function SetVolume( channel:int,volume:Number ):int{
		var chan:gxtkChannel=channels[channel];
		
		chan.transform.volume=volume;

		if( chan.state==1 ) chan.channel.soundTransform=chan.transform;

		return 0;
	}
	
	public function SetPan( channel:int,pan:Number ):int{
		var chan:gxtkChannel=channels[channel];
		
		chan.transform.pan=pan;

		if( chan.state==1 ) chan.channel.soundTransform=chan.transform;

		return 0;
	}
	
	public function SetRate( channel:int,rate:Number ):int{
		return -1;
	}
	
	public function PlayMusic( path:String,flags:int ):int{
		StopMusic();
		
		music=LoadSample( path );
		if( !music ) return -1;
		
		PlaySample( music,32,flags );
		return 0;
	}
	
	public function StopMusic():int{
		StopChannel( 32 );
		
		if( music ){
			music.Discard();
			music=null;
		}
		return 0;
	}
	
	public function PauseMusic():int{
		PauseChannel( 32 );
		
		return 0;
	}
	
	public function ResumeMusic():int{
		ResumeChannel( 32 );
		
		return 0;
	}
	
	public function MusicState():int{
		return ChannelState( 32 );
	}
	
	public function SetMusicVolume( volume:Number ):int{
		SetVolume( 32,volume );
		return 0;
	}
}

class gxtkSample{

	internal var sound:Sound;

	function gxtkSample( sound:Sound ){
		this.sound=sound;
	}
	
	public function Discard():int{
		return 0;
	}
	
}


class BBThread{

	internal var result:Object=null;
	internal var running:Boolean=false;
	
	public function Start():void{
		result=null;
		running=true;
		Run__UNSAFE__();
	}
	
	public function IsRunning():Boolean{
		return running;
	}
	
	public function Result():Object{
		return result;
	}
	
	public function Run__UNSAFE__():void{
		running=false;
	}
}


class BBAsyncImageLoaderThread{

	internal var _running:Boolean=false;
	
	internal var _device:gxtkGraphics;
	internal var _path:String;
	internal var _surface:gxtkSurface;

	public function Start():void{
		
		var thread:BBAsyncImageLoaderThread=this;
		
		var loader:Loader=new Loader();
		
		loader.contentLoaderInfo.addEventListener( Event.COMPLETE,onLoaded );
		loader.contentLoaderInfo.addEventListener( IOErrorEvent.IO_ERROR,onIoError );
		loader.contentLoaderInfo.addEventListener( SecurityErrorEvent.SECURITY_ERROR,onSecurityError );
		
		function onLoaded( e:Event ):void{
			thread._surface=new gxtkSurface( e.target.content );
			thread._running=false;
		}
		
		function onIoError( e:IOErrorEvent ):void{
			thread._surface=null;
			thread._running=false;
		}

		function onSecurityError( e:SecurityErrorEvent ):void{
			thread._surface=null;
			thread._running=false;
		}
		
		thread._running=true;
		
		loader.load( new URLRequest( BBGame.Game().PathToUrl( thread._path ) ) );
	}
	
	public function IsRunning():Boolean{
		return _running;
	}
}


class BBAsyncSoundLoaderThread{

	internal var _running:Boolean;
	
	internal var _device:gxtkAudio;
	internal var _path:String;
	internal var _sample:gxtkSample;

	public function Start():void{
		
		var thread:BBAsyncSoundLoaderThread=this;
		
		var sound:Sound=new Sound();
		
		sound.addEventListener( Event.COMPLETE,onLoaded );
		sound.addEventListener( IOErrorEvent.IO_ERROR,onIoError );
		sound.addEventListener( SecurityErrorEvent.SECURITY_ERROR,onSecurityError );
		
		function onLoaded( e:Event ):void{
			thread._sample=new gxtkSample( sound );
			thread._running=false;
		}
		
		function onIoError( e:IOErrorEvent ):void{
			thread._sample=null;
			thread._running=false;
		}

		function onSecurityError( e:SecurityErrorEvent ):void{
			thread._sample=null;
			thread._running=false;
		}
		
		thread._running=true;
		
		sound.load( new URLRequest( BBGame.Game().PathToUrl( thread._path ) ) );
	}
	
	public function IsRunning():Boolean{
		return _running;
	}
}


class BBDataBuffer{

	internal var _data:ByteArray=null;
	internal var _length:int=0;
	
	public function _Init( data:ByteArray ):void{
		_data=data;
		_length=data.length;
	}
	
	public function _New( length:int ):Boolean{
		if( _data ) return false
		_data=new ByteArray;
		_data.length=length;
		_length=length;
		return true;
	}
	
	public function _Load( path:String ):Boolean{
		if( _data ) return false
		var data:ByteArray=BBGame.Game().LoadData( path );
		if( !data ) return false;
		_Init( data );
		return true;
	}
	
	public function _LoadAsync( path:String,thread:BBThread ):void{

		var buf:BBDataBuffer=this;
		
		var loader:URLLoader=new URLLoader();
		loader.dataFormat=URLLoaderDataFormat.BINARY;
		loader.addEventListener( Event.COMPLETE,onLoaded );
		loader.addEventListener( IOErrorEvent.IO_ERROR,onError );
		
		function onLoaded( e:Event ):void{
			buf._Init( loader.data );
			thread.result=buf;
			thread.running=false;
		}
		
		function onError( e:IOErrorEvent ):void{
			thread.running=false;
		}
		
		loader.load( new URLRequest( BBGame.Game().PathToUrl( path ) ) );
	}

	public function GetByteArray():ByteArray{
		return _data;
	}
	
	public function Discard():void{
		if( _data ){
			_data.clear();
			_data=null;
			_length=0;
		}
	}
	
	public function Length():int{
		return _length;
	}
	
	public function PokeByte( addr:int,value:int ):void{
		_data.position=addr;
		_data.writeByte( value );
	}
	
	public function PokeShort( addr:int,value:int ):void{
		_data.position=addr;
		_data.writeShort( value );
	}
	
	public function PokeInt( addr:int,value:int ):void{
		_data.position=addr;
		_data.writeInt( value );
	}
	
	public function PokeFloat( addr:int,value:Number ):void{
		_data.position=addr;
		_data.writeFloat( value );
	}
	
	public function PeekByte( addr:int ):int{
		_data.position=addr;
		return _data.readByte();
	}
	
	public function PeekShort( addr:int ):int{
		_data.position=addr;
		return _data.readShort();
	}

	public function PeekInt( addr:int ):int{
		_data.position=addr;
		return _data.readInt();
	}
	
	public function PeekFloat( addr:int ):Number{
		_data.position=addr;
		return _data.readFloat();
	}
}


import flash.display.Stage3D;
import flash.display3D.*;
import flash.display3D.textures.Texture;
import flash.system.Capabilities;
//import com.adobe.utils.AGALMiniAssembler;

class EmptyNullClass extends gxtkSurface
{
	protected var bitmap_null:Bitmap = new Bitmap;
	
	override public function EmptyNullClass() {
		super(bitmap_null);
	};
	
	override public function Width():int {return 0;};
	override public function Height():int {return 0;};
	override public function Discard():int {return 0;};
	override public function Loaded():int {return 1;};
	override public function OnUnsafeLoadComplete():Boolean {return true;};
};

class Driver3D
{
	protected var game:BBFlashGame;
	protected var stage:Stage;
	
	public var context3d:Context3D;
	//protected var program:Program3D;
	protected var vertexbuffer:VertexBuffer3D;
	protected var indexbuffer:IndexBuffer3D;
	
	protected var width:int, height:int, alias:int;
	protected var contextReady:Boolean = false;
	
	private static var mojo_clear:Boolean = false;
	
	public function SetContext__(c:Context3D):void {
		context3d = c;
	}
	public function GetContext__():Context3D {
		return context3d;
	}
	
	public function CheckVersion():String
	{
		return Capabilities.version;
	}
	
	public function EnableErrorChecking_(b:Boolean):void {
		context3d.enableErrorChecking = b;
	}
	
	public function InitContext(w:int, h:int, al:int, flags:int):void {
		width = w; height = h; alias = al;
		
		game=BBFlashGame.FlashGame();
		stage=game.GetDisplayObjectContainer().stage;

		stage.stage3Ds[0].addEventListener( Event.CONTEXT3D_CREATE, Init3D );
		stage.stage3Ds[0].addEventListener( ErrorEvent.ERROR, contextCreationError );
		stage.stage3Ds[0].requestContext3D(); //auto, profile=baseline
		
		
	}
	
	public function Init3D(e:Event):void {
		//print("**************");
		context3d = stage.stage3Ds[0].context3D;			
		context3d.configureBackBuffer(width, height, alias, true);
		contextReady = true;
	}
	
	public function ContextReady():Boolean {
		return contextReady;
	}
	
	private function contextCreationError( error:ErrorEvent ):void
	{
		trace( error.errorID + ": " + error.text );
	}
	
	
	public  function UploadTextureData(tex:Texture, pix:TPixmap, miplevel:uint):int {
		try {
			tex.uploadFromBitmapData(pix.pixels, miplevel);
		} catch (e:Error) {
			//ran out of memory or pixels are gone
			return 0;
		}
		return 1;
	}
	

	public  function UploadConstantsFromArray( programType:String, firstRegister:int, data:Array, byteArrayOffset:uint):void {
		
		if (firstRegister >-1) {

			var mvec:Vector.<Number> = Vector.<Number>(data);
			//for (var i:int=0; i< (data.length); i++) { print (mvec[i].toString()); };
			
			context3d.setProgramConstantsFromVector(programType, firstRegister, mvec, data.length >> 2);
		};
	}
	
	
	public  function UploadIndexFromDataBuffer(ib:IndexBuffer3D, data:BBDataBuffer, byteArrayOffset:int, startVertex:int, numVertices:int):void {
//print("indexlen");
//print(String(data._data.length));
//print(data.Length().toString());	
		var d:ByteArray = data.GetByteArray();
		d.endian = Endian.LITTLE_ENDIAN;
		d.position=0;
		ib.uploadFromByteArray(d , byteArrayOffset, startVertex, numVertices);
		
	}
	
	public  function UploadVertexFromDataBuffer(vb:VertexBuffer3D, data:BBDataBuffer, byteArrayOffset:int, startVertex:int, numVertices:int):void {
//print("vblen");
//print(String(data._data.length));
//print(data.Length().toString());
		var d:ByteArray = data.GetByteArray();
		d.endian = Endian.LITTLE_ENDIAN;
		d.position=0;
		vb.uploadFromByteArray(d , byteArrayOffset, startVertex, numVertices);
		
	}
	
	public  function SetScissorRectangle_(x:int,y:int,w:int,h:int):void {
		context3d.setScissorRectangle( new Rectangle(x,y,w,h) );
	}
	
	public function Present():void {
		context3d.present();
	}
	
	public function PresentToDevice(g:gxtkGraphics):void {
		// ugh.... may break if mojo changes
		//context3d.drawToBitmapData( app.graphics.bitmapData );
		//if (!g.bitmap.bitmapData.transparent) {
			//g.bitmap.bitmapData=new BitmapData( stage.stageWidth,stage.stageHeight,true,0x00505050 );
			//mojo_clear = true
			//if (game.GetDisplayObjectContainer().contains(g.bitmap)) { game.GetDisplayObjectContainer().removeChild(g.bitmap);}
		//}
		context3d.present();
	}

	public static function DataBufferLittleEndian(b:BBDataBuffer):void {
		b.GetByteArray().endian = Endian.LITTLE_ENDIAN;
	}
	
	public function ForceDeviceTransparency(g:gxtkGraphics):void {
		g.bitmap.bitmapData=new BitmapData( stage.stageWidth,stage.stageHeight,true,0x00505050 );
		//if (game.GetDisplayObjectContainer().contains(g.bitmap)) { game.GetDisplayObjectContainer().removeChild(g.bitmap);}
		//print("xxx");
	}

}
/*
Copyright (c) 2011, Adobe Systems Incorporated
All rights reserved.

Redistribution and use in source and binary forms, with or without 
modification, are permitted provided that the following conditions are
met:

* Redistributions of source code must retain the above copyright notice, 
this list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the 
documentation and/or other materials provided with the distribution.

* Neither the name of Adobe Systems Incorporated nor the names of its 
contributors may be used to endorse or promote products derived from 
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/


	// ===========================================================================
	//	Imports
	// ---------------------------------------------------------------------------
	//import flash.display3D.*;
	import flash.utils.*;
	
	// ===========================================================================
	//	Class
	// ---------------------------------------------------------------------------
	 class AGALMiniAssembler
	{
		// ======================================================================
		//	Properties
		// ----------------------------------------------------------------------
		// AGAL bytes and error buffer 
		private var _agalcode:ByteArray							= null;
		private var _error:String								= "";
		
		private var debugEnabled:Boolean						= false;
		
		private static var initialized:Boolean					= false;
		
		// ======================================================================
		//	Getters
		// ----------------------------------------------------------------------
		public function get error():String						{ return _error; }
		public function get agalcode():ByteArray				{ return _agalcode; }
		
		// ======================================================================
		//	Constructor
		// ----------------------------------------------------------------------
		public function AGALMiniAssembler( debugging:Boolean = false ):void
		{
			debugEnabled = debugging;
			if ( !initialized )
				init();
		}
		// ======================================================================
		//	Methods
		// ----------------------------------------------------------------------
		public function assemble( mode:String, source:String, verbose:Boolean = false ):ByteArray
		{
			var start:uint = getTimer();
			
			_agalcode = new ByteArray();			
			_error = "";
			
			var isFrag:Boolean = false;
			
			if ( mode == FRAGMENT )
				isFrag = true
			else if ( mode != VERTEX )
				_error = 'ERROR: mode needs to be "' + FRAGMENT + '" or "' + VERTEX + '" but is "' + mode + '".';
			
			agalcode.endian = Endian.LITTLE_ENDIAN;
			agalcode.writeByte( 0xa0 );				// tag version
			agalcode.writeUnsignedInt( 0x1 );		// AGAL version, big endian, bit pattern will be 0x01000000
			agalcode.writeByte( 0xa1 );				// tag program id
			agalcode.writeByte( isFrag ? 1 : 0 );	// vertex or fragment
			
			var lines:Array = source.replace( /[\f\n\r\v]+/g, "\n" ).split( "\n" );
			var nest:int = 0;
			var nops:int = 0;
			var i:int;
			var lng:int = lines.length;
			
			for ( i = 0; i < lng && _error == ""; i++ )
			{
				var line:String = new String( lines[i] );
				
				// remove comments
				var startcomment:int = line.search( "//" );
				if ( startcomment != -1 )
					line = line.slice( 0, startcomment );
				
				// grab options
				var optsi:int = line.search( /<.*>/g );
				var opts:Array;
				if ( optsi != -1 )
				{
					opts = line.slice( optsi ).match( /([\w\.\-\+]+)/gi );
					line = line.slice( 0, optsi );
				}
				
				// find opcode
				var opCode:Array = line.match( /^\w{3}/ig );
				var opFound:OpCode = OPMAP[ opCode[0] ];
				
				// if debug is enabled, output the opcodes
				if ( debugEnabled )
					trace( opFound );
				
				if ( opFound == null )
				{
					if ( line.length >= 3 )
						print( "warning: bad line "+i+": "+lines[i] );
					continue;
				}
				
				line = line.slice( line.search( opFound.name ) + opFound.name.length );
				
				// nesting check
				if ( opFound.flags & OP_DEC_NEST )
				{
					nest--;
					if ( nest < 0 )
					{
						_error = "error: conditional closes without open.";
						break;
					}
				}
				if ( opFound.flags & OP_INC_NEST )
				{
					nest++;
					if ( nest > MAX_NESTING )
					{
						_error = "error: nesting to deep, maximum allowed is "+MAX_NESTING+".";
						break;
					}
				}
				if ( ( opFound.flags & OP_FRAG_ONLY ) && !isFrag )
				{
					_error = "error: opcode is only allowed in fragment programs.";
					break;
				}
				if ( verbose )
					print( "emit opcode=" + opFound );
				
				agalcode.writeUnsignedInt( opFound.emitCode );
				nops++;
				
				if ( nops > MAX_OPCODES )
				{
					_error = "error: too many opcodes. maximum is "+MAX_OPCODES+".";
					break;
				}
				
				// get operands, use regexp
				var regs:Array = line.match( /vc\[([vof][actps]?)(\d*)?(\.[xyzw](\+\d{1,3})?)?\](\.[xyzw]{1,4})?|([vof][actps]?)(\d*)?(\.[xyzw]{1,4})?/gi );
				if ( regs.length != opFound.numRegister )
				{
					_error = "error: wrong number of operands. found "+regs.length+" but expected "+opFound.numRegister+".";
					break;
				}
				
				var badreg:Boolean	= false;
				var pad:uint		= 64 + 64 + 32;
				var regLength:uint	= regs.length;
				
				for ( var j:int = 0; j < regLength; j++ )
				{
					var isRelative:Boolean = false;
					var relreg:Array = regs[ j ].match( /\[.*\]/ig );
					if ( relreg.length > 0 )
					{
						regs[ j ] = regs[ j ].replace( relreg[ 0 ], "0" );
						
						if ( verbose )
							print( "IS REL" );
						isRelative = true;
					}
					
					var res:Array = regs[j].match( /^\b[A-Za-z]{1,2}/ig );
					var regFound:Register = REGMAP[ res[ 0 ] ];
					
					// if debug is enabled, output the registers
					if ( debugEnabled )
						trace( regFound );
					
					if ( regFound == null )
					{
						_error = "error: could not parse operand "+j+" ("+regs[j]+").";
						badreg = true;
						break;
					}
					
					if ( isFrag )
					{
						if ( !( regFound.flags & REG_FRAG ) )
						{
							_error = "error: register operand "+j+" ("+regs[j]+") only allowed in vertex programs.";
							badreg = true;
							break;
						}
						if ( isRelative )
						{
							_error = "error: register operand "+j+" ("+regs[j]+") relative adressing not allowed in fragment programs.";
							badreg = true;
							break;
						}			
					}
					else
					{
						if ( !( regFound.flags & REG_VERT ) )
						{
							_error = "error: register operand "+j+" ("+regs[j]+") only allowed in fragment programs.";
							badreg = true;
							break;
						}
					}
					
					regs[j] = regs[j].slice( regs[j].search( regFound.name ) + regFound.name.length );
					//print( "REGNUM: " +regs[j] );
					var idxmatch:Array = isRelative ? relreg[0].match( /\d+/ ) : regs[j].match( /\d+/ );
					var regidx:uint = 0;
					
					if ( idxmatch )
						regidx = uint( idxmatch[0] );
					
					if ( regFound.range < regidx )
					{
						_error = "error: register operand "+j+" ("+regs[j]+") index exceeds limit of "+(regFound.range+1)+".";
						badreg = true;
						break;
					}
					
					var regmask:uint		= 0;
					var maskmatch:Array		= regs[j].match( /(\.[xyzw]{1,4})/ );
					var isDest:Boolean		= ( j == 0 && !( opFound.flags & OP_NO_DEST ) );
					var isSampler:Boolean	= ( j == 2 && ( opFound.flags & OP_SPECIAL_TEX ) );
					var reltype:uint		= 0;
					var relsel:uint			= 0;
					var reloffset:int		= 0;
					
					if ( isDest && isRelative )
					{
						_error = "error: relative can not be destination";	
						badreg = true; 
						break;								
					}
					
					if ( maskmatch )
					{
						regmask = 0;
						var cv:uint; 
						var maskLength:uint = maskmatch[0].length;
						for ( var k:int = 1; k < maskLength; k++ )
						{
							cv = maskmatch[0].charCodeAt(k) - "x".charCodeAt(0);
							if ( cv > 2 )
								cv = 3;
							if ( isDest )
								regmask |= 1 << cv;
							else
								regmask |= cv << ( ( k - 1 ) << 1 );
						}
						if ( !isDest )
							for ( ; k <= 4; k++ )
								regmask |= cv << ( ( k - 1 ) << 1 ) // repeat last								
					}
					else
					{
						regmask = isDest ? 0xf : 0xe4; // id swizzle or mask						
					}
					
					if ( isRelative )
					{
						var relname:Array = relreg[0].match( /[A-Za-z]{1,2}/ig );						
						var regFoundRel:Register = REGMAP[ relname[0]];						
						if ( regFoundRel == null )
						{ 
							_error = "error: bad index register"; 
							badreg = true; 
							break;
						}
						reltype = regFoundRel.emitCode;
						var selmatch:Array = relreg[0].match( /(\.[xyzw]{1,1})/ );						
						if ( selmatch.length==0 )
						{
							_error = "error: bad index register select"; 
							badreg = true; 
							break;						
						}
						relsel = selmatch[0].charCodeAt(1) - "x".charCodeAt(0);
						if ( relsel > 2 )
							relsel = 3; 
						var relofs:Array = relreg[0].match( /\+\d{1,3}/ig );
						if ( relofs.length > 0 ) 
							reloffset = relofs[0]; 						
						if ( reloffset < 0 || reloffset > 255 )
						{
							_error = "error: index offset "+reloffset+" out of bounds. [0..255]"; 
							badreg = true; 
							break;							
						}
						if ( verbose )
							print( "RELATIVE: type="+reltype+"=="+relname[0]+" sel="+relsel+"=="+selmatch[0]+" idx="+regidx+" offset="+reloffset ); 
					}
					
					if ( verbose )
						print( "  emit argcode="+regFound+"["+regidx+"]["+regmask+"]" );
					if ( isDest )
					{												
						agalcode.writeShort( regidx );
						agalcode.writeByte( regmask );
						agalcode.writeByte( regFound.emitCode );
						pad -= 32; 
					} else
					{
						if ( isSampler )
						{
							if ( verbose )
								print( "  emit sampler" );
							var samplerbits:uint = 5; // type 5 
							var optsLength:uint = opts.length;
							var bias:Number = 0; 
							for ( k = 0; k<optsLength; k++ )
							{
								if ( verbose )
									print( "    opt: "+opts[k] );
								var optfound:Sampler = SAMPLEMAP [opts[k]];
								if ( optfound == null )
								{
									// todo check that it's a number...
									//print( "Warning, unknown sampler option: "+opts[k] );
									bias = Number(opts[k]); 
									if ( verbose )
										print( "    bias: " + bias );																	
								}
								else
								{
									if ( optfound.flag != SAMPLER_SPECIAL_SHIFT )
										samplerbits &= ~( 0xf << optfound.flag );										
									samplerbits |= uint( optfound.mask ) << uint( optfound.flag );
								}
							}
							agalcode.writeShort( regidx );
							agalcode.writeByte(int(bias*8.0));
							agalcode.writeByte(0);							
							agalcode.writeUnsignedInt( samplerbits );
							
							if ( verbose )
								print( "    bits: " + ( samplerbits - 5 ) );
							pad -= 64;
						}
						else
						{
							if ( j == 0 )
							{
								agalcode.writeUnsignedInt( 0 );
								pad -= 32;
							}
							agalcode.writeShort( regidx );
							agalcode.writeByte( reloffset );
							agalcode.writeByte( regmask );
							agalcode.writeByte( regFound.emitCode );
							agalcode.writeByte( reltype );
							agalcode.writeShort( isRelative ? ( relsel | ( 1 << 15 ) ) : 0 );
							
							pad -= 64;
						}
					}
				}
				
				// pad unused regs
				for ( j = 0; j < pad; j += 8 ) 
					agalcode.writeByte( 0 );
				
				if ( badreg )
					break;
			}
			
			if ( _error != "" )
			{
				_error += "\n  at line " + i + " " + lines[i];
				agalcode.length = 0;
				print( _error );
			}
			
			// trace the bytecode bytes if debugging is enabled
			if ( debugEnabled )
			{
				var dbgLine:String = "generated bytecode:";
				var agalLength:uint = agalcode.length;
				for ( var index:uint = 0; index < agalLength; index++ )
				{
					if ( !( index % 16 ) )
						dbgLine += "\n";
					if ( !( index % 4 ) )
						dbgLine += " ";
					
					var byteStr:String = agalcode[ index ].toString( 16 );
					if ( byteStr.length < 2 )
						byteStr = "0" + byteStr;
					
					dbgLine += byteStr;
				}
				print( dbgLine );
			}
			
			if ( verbose )
				print( "AGALMiniAssembler.assemble time: " + ( ( getTimer() - start ) / 1000 ) + "s" );
			
			return agalcode;
		}
		
		static private function init():void
		{
			initialized = true;
			
			// Fill the dictionaries with opcodes and registers
			OPMAP[ MOV ] = new OpCode( MOV, 2, 0x00, 0 );
			OPMAP[ ADD ] = new OpCode( ADD, 3, 0x01, 0 );
			OPMAP[ SUB ] = new OpCode( SUB, 3, 0x02, 0 );
			OPMAP[ MUL ] = new OpCode( MUL, 3, 0x03, 0 );
			OPMAP[ DIV ] = new OpCode( DIV, 3, 0x04, 0 );
			OPMAP[ RCP ] = new OpCode( RCP, 2, 0x05, 0 );					
			OPMAP[ MIN ] = new OpCode( MIN, 3, 0x06, 0 );
			OPMAP[ MAX ] = new OpCode( MAX, 3, 0x07, 0 );
			OPMAP[ FRC ] = new OpCode( FRC, 2, 0x08, 0 );			
			OPMAP[ SQT ] = new OpCode( SQT, 2, 0x09, 0 );
			OPMAP[ RSQ ] = new OpCode( RSQ, 2, 0x0a, 0 );
			OPMAP[ POW ] = new OpCode( POW, 3, 0x0b, 0 );
			OPMAP[ LOG ] = new OpCode( LOG, 2, 0x0c, 0 );
			OPMAP[ EXP ] = new OpCode( EXP, 2, 0x0d, 0 );
			OPMAP[ NRM ] = new OpCode( NRM, 2, 0x0e, 0 );
			OPMAP[ SIN ] = new OpCode( SIN, 2, 0x0f, 0 );
			OPMAP[ COS ] = new OpCode( COS, 2, 0x10, 0 );
			OPMAP[ CRS ] = new OpCode( CRS, 3, 0x11, 0 );
			OPMAP[ DP3 ] = new OpCode( DP3, 3, 0x12, 0 );
			OPMAP[ DP4 ] = new OpCode( DP4, 3, 0x13, 0 );					
			OPMAP[ ABS ] = new OpCode( ABS, 2, 0x14, 0 );
			OPMAP[ NEG ] = new OpCode( NEG, 2, 0x15, 0 );
			OPMAP[ SAT ] = new OpCode( SAT, 2, 0x16, 0 );
			OPMAP[ M33 ] = new OpCode( M33, 3, 0x17, OP_SPECIAL_MATRIX );
			OPMAP[ M44 ] = new OpCode( M44, 3, 0x18, OP_SPECIAL_MATRIX );
			OPMAP[ M34 ] = new OpCode( M34, 3, 0x19, OP_SPECIAL_MATRIX );			
			OPMAP[ IFZ ] = new OpCode( IFZ, 1, 0x1a, OP_NO_DEST | OP_INC_NEST | OP_SCALAR );
			OPMAP[ INZ ] = new OpCode( INZ, 1, 0x1b, OP_NO_DEST | OP_INC_NEST | OP_SCALAR );
			OPMAP[ IFE ] = new OpCode( IFE, 2, 0x1c, OP_NO_DEST | OP_INC_NEST | OP_SCALAR );
			OPMAP[ INE ] = new OpCode( INE, 2, 0x1d, OP_NO_DEST | OP_INC_NEST | OP_SCALAR );
			OPMAP[ IFG ] = new OpCode( IFG, 2, 0x1e, OP_NO_DEST | OP_INC_NEST | OP_SCALAR );
			OPMAP[ IFL ] = new OpCode( IFL, 2, 0x1f, OP_NO_DEST | OP_INC_NEST | OP_SCALAR );
			OPMAP[ IEG ] = new OpCode( IEG, 2, 0x20, OP_NO_DEST | OP_INC_NEST | OP_SCALAR );
			OPMAP[ IEL ] = new OpCode( IEL, 2, 0x21, OP_NO_DEST | OP_INC_NEST | OP_SCALAR );
			OPMAP[ ELS ] = new OpCode( ELS, 0, 0x22, OP_NO_DEST | OP_INC_NEST | OP_DEC_NEST );
			OPMAP[ EIF ] = new OpCode( EIF, 0, 0x23, OP_NO_DEST | OP_DEC_NEST );
			OPMAP[ REP ] = new OpCode( REP, 1, 0x24, OP_NO_DEST | OP_INC_NEST | OP_SCALAR );
			OPMAP[ ERP ] = new OpCode( ERP, 0, 0x25, OP_NO_DEST | OP_DEC_NEST );
			OPMAP[ BRK ] = new OpCode( BRK, 0, 0x26, OP_NO_DEST );
			OPMAP[ KIL ] = new OpCode( KIL, 1, 0x27, OP_NO_DEST | OP_FRAG_ONLY );
			OPMAP[ TEX ] = new OpCode( TEX, 3, 0x28, OP_FRAG_ONLY | OP_SPECIAL_TEX );
			OPMAP[ SGE ] = new OpCode( SGE, 3, 0x29, 0 );
			OPMAP[ SLT ] = new OpCode( SLT, 3, 0x2a, 0 );
			OPMAP[ SGN ] = new OpCode( SGN, 2, 0x2b, 0 );
			
			REGMAP[ VA ]	= new Register( VA,	"vertex attribute",		0x0,	7,		REG_VERT | REG_READ );
			REGMAP[ VC ]	= new Register( VC,	"vertex constant",		0x1,	127,	REG_VERT | REG_READ );
			REGMAP[ VT ]	= new Register( VT,	"vertex temporary",		0x2,	7,		REG_VERT | REG_WRITE | REG_READ );
			REGMAP[ OP ]	= new Register( OP,	"vertex output",		0x3,	0,		REG_VERT | REG_WRITE );
			REGMAP[ V ]		= new Register( V,	"varying",				0x4,	7,		REG_VERT | REG_FRAG | REG_READ | REG_WRITE );
			REGMAP[ FC ]	= new Register( FC,	"fragment constant",	0x1,	27,		REG_FRAG | REG_READ );
			REGMAP[ FT ]	= new Register( FT,	"fragment temporary",	0x2,	7,		REG_FRAG | REG_WRITE | REG_READ );
			REGMAP[ FS ]	= new Register( FS,	"texture sampler",		0x5,	7,		REG_FRAG | REG_READ );
			REGMAP[ OC ]	= new Register( OC,	"fragment output",		0x3,	0,		REG_FRAG | REG_WRITE );
			
			SAMPLEMAP[ D2 ]			= new Sampler( D2,			SAMPLER_DIM_SHIFT,		0 );
			SAMPLEMAP[ D3 ]			= new Sampler( D3,			SAMPLER_DIM_SHIFT,		2 );
			SAMPLEMAP[ CUBE ]		= new Sampler( CUBE,		SAMPLER_DIM_SHIFT,		1 );
			SAMPLEMAP[ MIPNEAREST ]	= new Sampler( MIPNEAREST,	SAMPLER_MIPMAP_SHIFT,	1 );
			SAMPLEMAP[ MIPLINEAR ]	= new Sampler( MIPLINEAR,	SAMPLER_MIPMAP_SHIFT,	2 );
			SAMPLEMAP[ MIPNONE ]	= new Sampler( MIPNONE,		SAMPLER_MIPMAP_SHIFT,	0 );
			SAMPLEMAP[ NOMIP ]		= new Sampler( NOMIP,		SAMPLER_MIPMAP_SHIFT,	0 );
			SAMPLEMAP[ NEAREST ]	= new Sampler( NEAREST,		SAMPLER_FILTER_SHIFT,	0 );
			SAMPLEMAP[ LINEAR ]		= new Sampler( LINEAR,		SAMPLER_FILTER_SHIFT,	1 );
			SAMPLEMAP[ CENTROID ]	= new Sampler( CENTROID,	SAMPLER_SPECIAL_SHIFT,	1 << 0 );
			SAMPLEMAP[ SINGLE ]		= new Sampler( SINGLE,		SAMPLER_SPECIAL_SHIFT,	1 << 1 );
			SAMPLEMAP[ DEPTH ]		= new Sampler( DEPTH,		SAMPLER_SPECIAL_SHIFT,	1 << 2 );
			SAMPLEMAP[ REPEAT ]		= new Sampler( REPEAT,		SAMPLER_REPEAT_SHIFT,	1 );
			SAMPLEMAP[ WRAP ]		= new Sampler( WRAP,		SAMPLER_REPEAT_SHIFT,	1 );
			SAMPLEMAP[ CLAMP ]		= new Sampler( CLAMP,		SAMPLER_REPEAT_SHIFT,	0 );
		}
		
		// ======================================================================
		//	Constants
		// ----------------------------------------------------------------------
		private static const OPMAP:Dictionary					= new Dictionary();
		private static const REGMAP:Dictionary					= new Dictionary();
		private static const SAMPLEMAP:Dictionary				= new Dictionary();
		
		private static const MAX_NESTING:int					= 4;
		private static const MAX_OPCODES:int					= 256;
		
		private static const FRAGMENT:String					= "fragment";
		private static const VERTEX:String						= "vertex";
		
		// masks and shifts
		private static const SAMPLER_DIM_SHIFT:uint				= 12;
		private static const SAMPLER_SPECIAL_SHIFT:uint			= 16;
		private static const SAMPLER_REPEAT_SHIFT:uint			= 20;
		private static const SAMPLER_MIPMAP_SHIFT:uint			= 24;
		private static const SAMPLER_FILTER_SHIFT:uint			= 28;
		
		// regmap flags
		private static const REG_WRITE:uint						= 0x1;
		private static const REG_READ:uint						= 0x2;
		private static const REG_FRAG:uint						= 0x20;
		private static const REG_VERT:uint						= 0x40;
		
		// opmap flags
		private static const OP_SCALAR:uint						= 0x1;
		private static const OP_INC_NEST:uint					= 0x2;
		private static const OP_DEC_NEST:uint					= 0x4;
		private static const OP_SPECIAL_TEX:uint				= 0x8;
		private static const OP_SPECIAL_MATRIX:uint				= 0x10;
		private static const OP_FRAG_ONLY:uint					= 0x20;
		private static const OP_VERT_ONLY:uint					= 0x40;
		private static const OP_NO_DEST:uint					= 0x80;
		
		// opcodes
		private static const MOV:String							= "mov";
		private static const ADD:String							= "add";
		private static const SUB:String							= "sub";
		private static const MUL:String							= "mul";
		private static const DIV:String							= "div";
		private static const RCP:String							= "rcp";
		private static const MIN:String							= "min";
		private static const MAX:String							= "max";
		private static const FRC:String							= "frc";
		private static const SQT:String							= "sqt";
		private static const RSQ:String							= "rsq";
		private static const POW:String							= "pow";
		private static const LOG:String							= "log";
		private static const EXP:String							= "exp";
		private static const NRM:String							= "nrm";
		private static const SIN:String							= "sin";
		private static const COS:String							= "cos";
		private static const CRS:String							= "crs";
		private static const DP3:String							= "dp3";
		private static const DP4:String							= "dp4";
		private static const ABS:String							= "abs";
		private static const NEG:String							= "neg";
		private static const SAT:String							= "sat";
		private static const M33:String							= "m33";
		private static const M44:String							= "m44";
		private static const M34:String							= "m34";
		private static const IFZ:String							= "ifz";
		private static const INZ:String							= "inz";
		private static const IFE:String							= "ife";
		private static const INE:String							= "ine";
		private static const IFG:String							= "ifg";
		private static const IFL:String							= "ifl";
		private static const IEG:String							= "ieg";
		private static const IEL:String							= "iel";
		private static const ELS:String							= "els";
		private static const EIF:String							= "eif";
		private static const REP:String							= "rep";
		private static const ERP:String							= "erp";
		private static const BRK:String							= "brk";
		private static const KIL:String							= "kil";
		private static const TEX:String							= "tex";
		private static const SGE:String							= "sge";
		private static const SLT:String							= "slt";
		private static const SGN:String							= "sgn";
		
		// registers
		private static const VA:String							= "va";
		private static const VC:String							= "vc";
		private static const VT:String							= "vt";
		private static const OP:String							= "op";
		private static const V:String							= "v";
		private static const FC:String							= "fc";
		private static const FT:String							= "ft";
		private static const FS:String							= "fs";
		private static const OC:String							= "oc";
		
		// samplers
		private static const D2:String							= "2d";
		private static const D3:String							= "3d";
		private static const CUBE:String						= "cube";
		private static const MIPNEAREST:String					= "mipnearest";
		private static const MIPLINEAR:String					= "miplinear";
		private static const MIPNONE:String						= "mipnone";
		private static const NOMIP:String						= "nomip";
		private static const NEAREST:String						= "nearest";
		private static const LINEAR:String						= "linear";
		private static const CENTROID:String					= "centroid";
		private static const SINGLE:String						= "single";
		private static const DEPTH:String						= "depth";
		private static const REPEAT:String						= "repeat";
		private static const WRAP:String						= "wrap";
		private static const CLAMP:String						= "clamp";
	}


// ================================================================================
//	Helper Classes
// --------------------------------------------------------------------------------

	// ===========================================================================
	//	Class
	// ---------------------------------------------------------------------------
	class OpCode
	{		
		// ======================================================================
		//	Properties
		// ----------------------------------------------------------------------
		private var _emitCode:uint;
		private var _flags:uint;
		private var _name:String;
		private var _numRegister:uint;
		
		// ======================================================================
		//	Getters
		// ----------------------------------------------------------------------
		public function get emitCode():uint		{ return _emitCode; }
		public function get flags():uint		{ return _flags; }
		public function get name():String		{ return _name; }
		public function get numRegister():uint	{ return _numRegister; }
		
		// ======================================================================
		//	Constructor
		// ----------------------------------------------------------------------
		public function OpCode( name:String, numRegister:uint, emitCode:uint, flags:uint)
		{
			_name = name;
			_numRegister = numRegister;
			_emitCode = emitCode;
			_flags = flags;
		}		
		
		// ======================================================================
		//	Methods
		// ----------------------------------------------------------------------
		public function toString():String
		{
			return "[OpCode name=\""+_name+"\", numRegister="+_numRegister+", emitCode="+_emitCode+", flags="+_flags+"]";
		}
	}
	
	// ===========================================================================
	//	Class
	// ---------------------------------------------------------------------------
	class Register
	{
		// ======================================================================
		//	Properties
		// ----------------------------------------------------------------------
		private var _emitCode:uint;
		private var _name:String;
		private var _longName:String;
		private var _flags:uint;
		private var _range:uint;
		
		// ======================================================================
		//	Getters
		// ----------------------------------------------------------------------
		public function get emitCode():uint		{ return _emitCode; }
		public function get longName():String	{ return _longName; }
		public function get name():String		{ return _name; }
		public function get flags():uint		{ return _flags; }
		public function get range():uint		{ return _range; }
		
		// ======================================================================
		//	Constructor
		// ----------------------------------------------------------------------
		public function Register( name:String, longName:String, emitCode:uint, range:uint, flags:uint)
		{
			_name = name;
			_longName = longName;
			_emitCode = emitCode;
			_range = range;
			_flags = flags;
		}
		
		// ======================================================================
		//	Methods
		// ----------------------------------------------------------------------
		public function toString():String
		{
			return "[Register name=\""+_name+"\", longName=\""+_longName+"\", emitCode="+_emitCode+", range="+_range+", flags="+ _flags+"]";
		}
	}
	
	// ===========================================================================
	//	Class
	// ---------------------------------------------------------------------------
	class Sampler
	{
		// ======================================================================
		//	Properties
		// ----------------------------------------------------------------------
		private var _flag:uint;
		private var _mask:uint;
		private var _name:String;
		
		// ======================================================================
		//	Getters
		// ----------------------------------------------------------------------
		public function get flag():uint		{ return _flag; }
		public function get mask():uint		{ return _mask; }
		public function get name():String	{ return _name; }
		
		// ======================================================================
		//	Constructor
		// ----------------------------------------------------------------------
		public function Sampler( name:String, flag:uint, mask:uint )
		{
			_name = name;
			_flag = flag;
			_mask = mask;
		}
		
		// ======================================================================
		//	Methods
		// ----------------------------------------------------------------------
		public function toString():String
		{
			return "[Sampler name=\""+_name+"\", flag=\""+_flag+"\", mask="+mask+"]";
		}
	}


import flash.display.Bitmap;
import flash.display.BitmapData;

class TPixmap {
	
	internal var pixels:BitmapData;
	internal var isLoaded:Boolean=false;
	internal var width:int;
	internal var height:int;
	
	
	private function onComplete (event:Event):void
	{
		pixels = Bitmap(LoaderInfo(event.target).content).bitmapData;
		isLoaded = true;
		width = pixels.width;
		height = pixels.height;
	}
	
	private function onError (e:IOErrorEvent):void
	{
		isLoaded = true;
		width=0; height=0;
	}
	
	
	public static function LoadImageData(file:String):TPixmap {
		var pix:TPixmap = new TPixmap;
		
		var loader:Loader = new Loader();
		loader.contentLoaderInfo.addEventListener(Event.COMPLETE, pix.onComplete);
		loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, pix.onError);
		loader.load(new URLRequest(file));

		return pix;
	}
	
	public static function CreatePixmap(x:int, y:int):TPixmap {
		var pix:TPixmap = new TPixmap;
		pix.pixels = new BitmapData(x, y, true, 0xffffffff);
		pix.width = x; pix.height = y;
		return pix;
	}
	
	public static function ReadPixel(pix:TPixmap, x:int, y:int):uint {
		return pix.pixels.getPixel32(x,y);
	}
	public static function WritePixel(pix:TPixmap, x:int, y:int, rgb:uint):void {
		pix.pixels.setPixel32(x,y, rgb);
	}
	
	public static function ResizePixmap(pix:TPixmap, nw:int, nh:int, smooth:Boolean):TPixmap {
		var newpix:TPixmap = new TPixmap;
		var mat:Matrix = new Matrix();
		
		mat.scale(nw/pix.pixels.width, nh/pix.pixels.height);
		newpix.pixels = new BitmapData(nw, nh, true, 0x00000000);
		newpix.pixels.draw(pix.pixels, mat, null, BlendMode.NORMAL, null, smooth);

		return newpix;
	}
	
	public static function MaskPixmap(pix:TPixmap, threshold:uint):TPixmap {
		
		var newpix:TPixmap = new TPixmap;

		newpix.pixels = new BitmapData(pix.pixels.width, pix.pixels.height, true);
		var pt:Point = new Point(0, 0);
		
		//pix.pixels.threshold(newpix.pixels, newpix.pixels.rect, pt, "==", threshold, 0x00000000, 0x00ffffff, true);
		newpix.pixels.threshold(pix.pixels, pix.pixels.rect, pt, "==", threshold, 0x00000000, 0x00ffffff, true);
		return newpix;
	}
	
	public static function GetInfo(pix:TPixmap):Array {
		return [pix.width, pix.height];
	}
	
	public static function CheckIsLoaded(pix:TPixmap):Boolean {
		return pix.isLoaded;
	}
}


class BBHttpRequest{

	internal var _req:URLRequest=null;
	internal var _loader:URLLoader=null;
	internal var _response:String="";
	internal var _status:int=-1;
	
	internal var _running:Boolean=false;

	public function Open( req:String,url:String ):void{
		_req=new URLRequest( url );
		_req.method=req;
		_response="";
		_status=-1;
	}
	
	public function SetHeader( name:String,value:String ):void{
		_req.requestHeaders.push( new URLRequestHeader( name,value ) );
	}
	
	public function Send():void{
		Start();
	}
	
	public function SendText( text:String,encoding:String ):void{
		_req.data=text;
		Start();
	}
	
	public function ResponseText():String{
		return _response;
	}
	
	public function Status():int{
		return _status;
	}
	
	public function BytesReceived():int{
		if( _loader ) return _loader.bytesLoaded;
		return 0;
	}
	
	public function IsRunning():Boolean{
		return _running;
	}
	
	internal function Start():void{
	
		var req:BBHttpRequest=this;
		
		_loader=new URLLoader( null );
		_loader.addEventListener( Event.COMPLETE,onComplete );
		_loader.addEventListener( IOErrorEvent.IO_ERROR,onError );
		_loader.addEventListener( HTTPStatusEvent.HTTP_STATUS,onStatus );

		var status:int=-1;
		
		function onComplete( e:Event ):void{
			req._response=_loader.data;
			req._status=status;
			req._running=false;
		}
		
		function onError( e:IOErrorEvent ):void{
			req._running=false;
		}

		function onStatus( e:HTTPStatusEvent ):void{
			status=e.status;
		}
		
		_running=true;
		_loader.load( _req );
	}
}
class c_App extends Object{
	public function m_App_new():c_App{
		if((bb_app2__app)!=null){
			error("App has already been created");
		}
		bb_app2__app=this;
		bb_app2__delegate=(new c_GameDelegate).m_GameDelegate_new();
		bb_app2__game.SetDelegate(bb_app2__delegate);
		return this;
	}
	public function p_OnResize():int{
		return 0;
	}
	public function p_OnCreate():int{
		return 0;
	}
	public function p_OnSuspend():int{
		return 0;
	}
	public function p_OnResume():int{
		return 0;
	}
	public function p_OnUpdate():int{
		return 0;
	}
	public function p_OnLoading():int{
		return 0;
	}
	public function p_OnRender():int{
		return 0;
	}
	public function p_OnClose():int{
		bb_app2_EndApp();
		return 0;
	}
	public function p_OnBack():int{
		this.p_OnClose();
		return 0;
	}
}
class c_MiniB3DApp extends c_App{
	public function m_MiniB3DApp_new():c_MiniB3DApp{
		super.m_App_new();
		return this;
	}
	internal var m_preload_list:c_StringList=(new c_StringList).m_StringList_new2();
	public function p_PreLoad(t_f:String):int{
		m_preload_list.p_AddLast4(t_f);
		return 0;
	}
	public function p_PreLoad2(t_f:Array):int{
		var t_:Array=t_f;
		var t_2:int=0;
		while(t_2<t_.length){
			var t_s:String=t_[t_2];
			t_2=t_2+1;
			m_preload_list.p_AddLast4(t_s);
		}
		return 0;
	}
	public function p_Create():int{
		return 0;
	}
	internal var m_init:int=0;
	public function p_Init():int{
		return 0;
	}
	public function p_Minib3dInit():void{
		if((m_init)!=0){
			return;
		}
		if(!((c_TPixmap.m_PreLoadPixmap(m_preload_list.p_ToArray()))!=0)){
			return;
		}
		m_init=1;
		this.p_Init();
		m_init=2;
	}
	public override function p_OnCreate():int{
		bb_app2_SetUpdateRate(30);
		bb_flash11_SetRender(0);
		this.p_PreLoad("mojo_font.png");
		this.p_Create();
		this.p_Minib3dInit();
		return 0;
	}
	public function p_Update():int{
		return 0;
	}
	internal var m_old_ms:int=0;
	internal var m_renders:int=0;
	internal var m_fps:int=0;
	public override function p_OnUpdate():int{
		if(!((m_init)!=0)){
			this.p_Minib3dInit();
			return 0;
		}
		this.p_Update();
		if(bb_app2_Millisecs()-m_old_ms>=1000){
			m_old_ms=bb_app2_Millisecs();
			m_fps=m_renders;
			m_renders=0;
		}
		return 0;
	}
	public function p_PreLoadRender():int{
		return 0;
	}
	internal static var m__resumed:Boolean;
	public function p_Render():int{
		return 0;
	}
	public override function p_OnRender():int{
		if(!((m_init)!=0)){
			this.p_PreLoadRender();
			return 0;
		}
		if(m__resumed){
			m__resumed=false;
		}
		this.p_Render();
		bb_functions_RenderWorld();
		m_renders=m_renders+1;
		return 0;
	}
	internal static var m__suspend:Boolean;
	public function p_Resume():int{
		return 0;
	}
	public override function p_OnResume():int{
		m__resumed=true;
		if(m__suspend){
			m__suspend=false;
		}
		this.p_Resume();
		return 0;
	}
}
class c_Game extends c_MiniB3DApp{
	public function m_Game_new():c_Game{
		super.m_MiniB3DApp_new();
		return this;
	}
	internal var m_hndlr:c_CalLoaderHandler=null;
	public override function p_OnCreate():int{
		bb_flash11_SetRender(0);
		bb_app2_SetUpdateRate(30);
		this.p_PreLoad("mojo_font.png");
		m_hndlr=(new c_CalLoaderHandler).m_CalLoaderHandler_new();
		m_hndlr.p_LoadFile("http://vigilsoft.net/democal3d/test.xsf",0,((new c_SKNCalSkeletonLoader).m_SKNCalSkeletonLoader_new()),"");
		m_hndlr.p_LoadFile("http://vigilsoft.net/democal3d/testpp.xmf",0,((new c_SKNCalMeshLoader).m_SKNCalMeshLoader_new()),"");
		m_hndlr.p_LoadFile("http://vigilsoft.net/democal3d/run.xaf",0,((new c_SKNCalAnimationLoader).m_SKNCalAnimationLoader_new()),"");
		m_hndlr.p_LoadFile("http://vigilsoft.net/democal3d/getxmlimage.php?a=paladin_chest.jpg",0,((new c_SKNCalImageLoader).m_SKNCalImageLoader_new()),"");
		return 0;
	}
	internal var m_CB3D:c_Cal3dB3d=null;
	internal var m_dt:c_DeltaTimer=null;
	internal var m_cam:c_TCamera=null;
	internal var m_light:c_TLight=null;
	internal var m_mesh:c_TMesh=null;
	internal var m_txt:c_TText=null;
	internal var m_init_gl:Boolean=false;
	public override function p_Init():int{
		m_CB3D=(new c_Cal3dB3d).m_Cal3dB3d_new();
		m_dt=(new c_DeltaTimer).m_DeltaTimer_new(30.0);
		m_cam=bb_functions_CreateCamera(null);
		m_cam.p_CameraClsColor(0.0,0.0,80.0);
		m_cam.p_PositionEntity(0.0,4.0,-50.0,0);
		m_cam.p_RotateEntity(-90.0,0.0,0.0,0);
		m_light=bb_functions_CreateLight(1,null);
		m_light.p_PositionEntity(0.0,3.0,-3.0,0);
		m_mesh=bb_functions_CreateCube(null);
		m_txt=c_TText.m_CreateText2D(null,"","",96,9,0);
		print("main: init done");
		m_init_gl=true;
		return 0;
	}
	internal var m_TestTexture:c_TTexture=null;
	internal var m_Cimg:c_CalImage=null;
	internal var m_touchBegin:int=0;
	internal var m_oldTouchX:int=0;
	internal var m_oldTouchY:int=0;
	internal var m_lr:Number=.0;
	internal var m_ud:Number=.0;
	public override function p_Update():int{
		if(((bb_input_KeyHit(432))!=0) || ((bb_input_KeyHit(27))!=0)){
			error("");
		}
		if(m_CB3D!=null){
			if(m_CB3D.m_isloaded==false){
				if(m_hndlr.p_IsFileLoaded("http://vigilsoft.net/democal3d/test.xsf")==true && m_hndlr.p_IsFileLoaded("http://vigilsoft.net/democal3d/testpp.xmf")==true && m_hndlr.p_IsFileLoaded("http://vigilsoft.net/democal3d/run.xaf")==true){
					m_CB3D.p_SetSkeleton((m_hndlr.p_GetLoadedFile("http://vigilsoft.net/democal3d/test.xsf",true)) as c_CalCoreSkeleton);
					m_CB3D.p_AddMesh((m_hndlr.p_GetLoadedFile("http://vigilsoft.net/democal3d/testpp.xmf",true)) as c_CalCoreMesh);
					m_CB3D.p_AddAnim((m_hndlr.p_GetLoadedFile("http://vigilsoft.net/democal3d/run.xaf",true)) as c_CalCoreAnimation);
					print("Building Mesh");
					m_CB3D.p_Build();
					m_CB3D.m_CModel.p_getMixer().p_blendCycle(0,1.0,0.0);
					m_CB3D.m_isloaded=true;
				}
			}else{
				m_CB3D.p_Update3(m_dt.m_delta/30.0);
			}
		}
		if(m_TestTexture==null){
			if(m_hndlr.p_IsFileLoaded("http://vigilsoft.net/democal3d/getxmlimage.php?a=paladin_chest.jpg")==true){
				m_Cimg=((m_hndlr.p_GetLoadedFile("http://vigilsoft.net/democal3d/getxmlimage.php?a=paladin_chest.jpg",true)) as c_CalImage);
			}
		}
		if(m_Cimg!=null){
			if(m_Cimg.p_IsFinished()==false){
				m_Cimg.p_Update();
			}else{
				bb_functions_EntityTexture((m_CB3D.m_B3dModel),m_Cimg.m_texture,0,0);
				var t_:c_Enumerator13=m_CB3D.m_Meshes.p_ObjectEnumerator();
				while(t_.p_HasNext()){
					var t_msh:c_Cal3dB3dMesh=t_.p_NextObject();
					bb_functions_EntityTexture((t_msh.m_B3dMesh),m_Cimg.m_texture,0,0);
				}
				bb_functions_EntityTexture((m_mesh),m_Cimg.m_texture,0,0);
			}
		}
		bb_asyncevent_UpdateAsyncEvents();
		m_hndlr.p_Update();
		m_dt.p_UpdateDelta();
		var t_cr:Number=(bb_input_KeyDown(37)-bb_input_KeyDown(39));
		var t_cu:Number=(bb_input_KeyDown(40)-bb_input_KeyDown(38));
		var t_camin:Number=(bb_input_KeyDown(87)-bb_input_KeyDown(83));
		var t_camup:Number=(bb_input_KeyDown(68)-bb_input_KeyDown(65));
		var t_turnzx:Number=(bb_input_KeyDown(90)-bb_input_KeyDown(88));
		if(((bb_input_TouchDown(0))!=0) && !((bb_input_TouchDown(1))!=0)){
			if(!((m_touchBegin)!=0)){
				m_oldTouchX=((bb_input_TouchX(0))|0);
				m_oldTouchY=((bb_input_TouchY(0))|0);
				m_touchBegin=1;
			}
			m_lr=(bb_input_TouchX(0)-(m_oldTouchX))*0.5;
			m_ud=(-bb_input_TouchY(0)+(m_oldTouchY))*0.5;
			m_oldTouchX=((bb_input_TouchX(0))|0);
			m_oldTouchY=((bb_input_TouchY(0))|0);
		}else{
			if((bb_input_TouchDown(1))!=0){
				if(!((m_touchBegin)!=0)){
					m_oldTouchX=((bb_input_TouchX(0))|0);
					m_oldTouchY=((bb_input_TouchY(0))|0);
					m_touchBegin=1;
				}
				t_camup=(-bb_input_TouchX(0)+(m_oldTouchX))*0.1;
				t_camin=(-bb_input_TouchY(0)+(m_oldTouchY))*0.1;
				m_oldTouchX=((bb_input_TouchX(0))|0);
				m_oldTouchY=((bb_input_TouchY(0))|0);
			}else{
				m_touchBegin=0;
			}
		}
		m_cam.p_MoveEntity(t_camup,0.0,t_camin);
		m_cam.p_TurnEntity(t_cu,t_cr,0.0,0);
		m_txt.p_SetText("Cam: "+String(t_camup)+" "+String(t_camin)+" "+String(t_cu)+" "+String(t_cr)+" delta: "+String(m_dt.m_delta),0.0,0.0,0.0,0);
		m_txt.p_HideEntity();
		m_txt.p_Draw(0.0,0.0,false);
		return 0;
	}
	public override function p_Render():int{
		bb_mojographics_SetMojoEmulation();
		return 0;
	}
}
var bb_app2__app:c_App;
class c_GameDelegate extends BBGameDelegate{
	public function m_GameDelegate_new():c_GameDelegate{
		return this;
	}
	internal var m__graphics:gxtkGraphics=null;
	internal var m__audio:gxtkAudio=null;
	internal var m__input:c_InputDevice=null;
	public override function StartGame():void{
		m__graphics=(new gxtkGraphics);
		bb_graphics_SetGraphicsDevice(m__graphics);
		bb_graphics_SetFont(null,32);
		m__audio=(new gxtkAudio);
		bb_audio_SetAudioDevice(m__audio);
		m__input=(new c_InputDevice).m_InputDevice_new();
		bb_input_SetInputDevice(m__input);
		bb_app2_ValidateDeviceWindow(false);
		bb_app2_EnumDisplayModes();
		bb_app2__app.p_OnCreate();
	}
	public override function SuspendGame():void{
		bb_app2__app.p_OnSuspend();
		m__audio.Suspend();
	}
	public override function ResumeGame():void{
		m__audio.Resume();
		bb_app2__app.p_OnResume();
	}
	public override function UpdateGame():void{
		bb_app2_ValidateDeviceWindow(true);
		m__input.p_BeginUpdate();
		bb_app2__app.p_OnUpdate();
		m__input.p_EndUpdate();
	}
	public override function RenderGame():void{
		bb_app2_ValidateDeviceWindow(true);
		var t_mode:int=m__graphics.BeginRender();
		if((t_mode)!=0){
			bb_graphics_BeginRender();
		}
		if(t_mode==2){
			bb_app2__app.p_OnLoading();
		}else{
			bb_app2__app.p_OnRender();
		}
		if((t_mode)!=0){
			bb_graphics_EndRender();
		}
		m__graphics.EndRender();
	}
	public override function KeyEvent(t_event:int,t_data:int):void{
		m__input.p_KeyEvent(t_event,t_data);
		if(t_event!=1){
			return;
		}
		var t_1:int=t_data;
		if(t_1==432){
			bb_app2__app.p_OnClose();
		}else{
			if(t_1==416){
				bb_app2__app.p_OnBack();
			}
		}
	}
	public override function MouseEvent(t_event:int,t_data:int,t_x:Number,t_y:Number):void{
		m__input.p_MouseEvent(t_event,t_data,t_x,t_y);
	}
	public override function TouchEvent(t_event:int,t_data:int,t_x:Number,t_y:Number):void{
		m__input.p_TouchEvent(t_event,t_data,t_x,t_y);
	}
	public override function MotionEvent(t_event:int,t_data:int,t_x:Number,t_y:Number,t_z:Number):void{
		m__input.p_MotionEvent(t_event,t_data,t_x,t_y,t_z);
	}
	public override function DiscardGraphics():void{
		m__graphics.DiscardGraphics();
	}
}
var bb_app2__delegate:c_GameDelegate;
var bb_app2__game:BBGame;
internal function bbMain():int{
	(new c_Game).m_Game_new();
	return 0;
}
var bb_graphics_device:gxtkGraphics;
internal function bb_graphics_SetGraphicsDevice(t_dev:gxtkGraphics):int{
	bb_graphics_device=t_dev;
	return 0;
}
class c_Image extends Object{
	internal static var m_DefaultFlags:int;
	public function m_Image_new():c_Image{
		return this;
	}
	internal var m_surface:gxtkSurface=null;
	internal var m_width:int=0;
	internal var m_height:int=0;
	internal var m_frames:Array=[];
	internal var m_flags:int=0;
	internal var m_tx:Number=.0;
	internal var m_ty:Number=.0;
	public function p_SetHandle(t_tx:Number,t_ty:Number):int{
		this.m_tx=t_tx;
		this.m_ty=t_ty;
		this.m_flags=this.m_flags&-2;
		return 0;
	}
	public function p_ApplyFlags(t_iflags:int):int{
		m_flags=t_iflags;
		if((m_flags&2)!=0){
			var t_:Array=m_frames;
			var t_2:int=0;
			while(t_2<t_.length){
				var t_f:c_Frame=t_[t_2];
				t_2=t_2+1;
				t_f.m_x+=1;
			}
			m_width-=2;
		}
		if((m_flags&4)!=0){
			var t_3:Array=m_frames;
			var t_4:int=0;
			while(t_4<t_3.length){
				var t_f2:c_Frame=t_3[t_4];
				t_4=t_4+1;
				t_f2.m_y+=1;
			}
			m_height-=2;
		}
		if((m_flags&1)!=0){
			this.p_SetHandle((m_width)/2.0,(m_height)/2.0);
		}
		if(m_frames.length==1 && m_frames[0].m_x==0 && m_frames[0].m_y==0 && m_width==m_surface.Width() && m_height==m_surface.Height()){
			m_flags|=65536;
		}
		return 0;
	}
	public function p_Init2(t_surf:gxtkSurface,t_nframes:int,t_iflags:int):c_Image{
		m_surface=t_surf;
		m_width=((m_surface.Width()/t_nframes)|0);
		m_height=m_surface.Height();
		m_frames=new_object_array(t_nframes);
		for(var t_i:int=0;t_i<t_nframes;t_i=t_i+1){
			m_frames[t_i]=(new c_Frame).m_Frame_new(t_i*m_width,0);
		}
		this.p_ApplyFlags(t_iflags);
		return this;
	}
	internal var m_source:c_Image=null;
	public function p_Init3(t_surf:gxtkSurface,t_x:int,t_y:int,t_iwidth:int,t_iheight:int,t_nframes:int,t_iflags:int,t_src:c_Image,t_srcx:int,t_srcy:int,t_srcw:int,t_srch:int):c_Image{
		m_surface=t_surf;
		m_source=t_src;
		m_width=t_iwidth;
		m_height=t_iheight;
		m_frames=new_object_array(t_nframes);
		var t_ix:int=t_x;
		var t_iy:int=t_y;
		for(var t_i:int=0;t_i<t_nframes;t_i=t_i+1){
			if(t_ix+m_width>t_srcw){
				t_ix=0;
				t_iy+=m_height;
			}
			if(t_ix+m_width>t_srcw || t_iy+m_height>t_srch){
				error("Image frame outside surface");
			}
			m_frames[t_i]=(new c_Frame).m_Frame_new(t_ix+t_srcx,t_iy+t_srcy);
			t_ix+=m_width;
		}
		this.p_ApplyFlags(t_iflags);
		return this;
	}
	public function p_Width():int{
		return m_width;
	}
}
class c_GraphicsContext extends Object{
	public function m_GraphicsContext_new():c_GraphicsContext{
		return this;
	}
	internal var m_defaultFont:c_Image=null;
	internal var m_font:c_Image=null;
	internal var m_firstChar:int=0;
	internal var m_matrixSp:int=0;
	internal var m_ix:Number=1.0;
	internal var m_iy:Number=.0;
	internal var m_jx:Number=.0;
	internal var m_jy:Number=1.0;
	internal var m_tx:Number=.0;
	internal var m_ty:Number=.0;
	internal var m_tformed:int=0;
	internal var m_matDirty:int=0;
	internal var m_color_r:Number=.0;
	internal var m_color_g:Number=.0;
	internal var m_color_b:Number=.0;
	internal var m_alpha:Number=.0;
	internal var m_blend:int=0;
	internal var m_scissor_x:Number=.0;
	internal var m_scissor_y:Number=.0;
	internal var m_scissor_width:Number=.0;
	internal var m_scissor_height:Number=.0;
}
var bb_graphics_context:c_GraphicsContext;
internal function bb_data_FixDataPath(t_path:String):String{
	var t_i:int=t_path.indexOf(":/",0);
	if(t_i!=-1 && t_path.indexOf("/",0)==t_i+1){
		return t_path;
	}
	if(string_startswith(t_path,"./") || string_startswith(t_path,"/")){
		return t_path;
	}
	return "monkey://data/"+t_path;
}
class c_Frame extends Object{
	internal var m_x:int=0;
	internal var m_y:int=0;
	public function m_Frame_new(t_x:int,t_y:int):c_Frame{
		this.m_x=t_x;
		this.m_y=t_y;
		return this;
	}
	public function m_Frame_new2():c_Frame{
		return this;
	}
}
internal function bb_graphics_LoadImage(t_path:String,t_frameCount:int,t_flags:int):c_Image{
	var t_surf:gxtkSurface=bb_graphics_device.LoadSurface(bb_data_FixDataPath(t_path));
	if((t_surf)!=null){
		return ((new c_Image).m_Image_new()).p_Init2(t_surf,t_frameCount,t_flags);
	}
	return null;
}
internal function bb_graphics_LoadImage2(t_path:String,t_frameWidth:int,t_frameHeight:int,t_frameCount:int,t_flags:int):c_Image{
	var t_surf:gxtkSurface=bb_graphics_device.LoadSurface(bb_data_FixDataPath(t_path));
	if((t_surf)!=null){
		return ((new c_Image).m_Image_new()).p_Init3(t_surf,0,0,t_frameWidth,t_frameHeight,t_frameCount,t_flags,null,0,0,t_surf.Width(),t_surf.Height());
	}
	return null;
}
internal function bb_graphics_SetFont(t_font:c_Image,t_firstChar:int):int{
	if(!((t_font)!=null)){
		if(!((bb_graphics_context.m_defaultFont)!=null)){
			bb_graphics_context.m_defaultFont=bb_graphics_LoadImage("mojo_font.png",96,2);
		}
		t_font=bb_graphics_context.m_defaultFont;
		t_firstChar=32;
	}
	bb_graphics_context.m_font=t_font;
	bb_graphics_context.m_firstChar=t_firstChar;
	return 0;
}
var bb_audio_device:gxtkAudio;
internal function bb_audio_SetAudioDevice(t_dev:gxtkAudio):int{
	bb_audio_device=t_dev;
	return 0;
}
class c_InputDevice extends Object{
	internal var m__joyStates:Array=new_object_array(4);
	public function m_InputDevice_new():c_InputDevice{
		for(var t_i:int=0;t_i<4;t_i=t_i+1){
			m__joyStates[t_i]=(new c_JoyState).m_JoyState_new();
		}
		return this;
	}
	internal var m__keyDown:Array=new_bool_array(512);
	internal var m__keyHitPut:int=0;
	internal var m__keyHitQueue:Array=new_number_array(33);
	internal var m__keyHit:Array=new_number_array(512);
	public function p_PutKeyHit(t_key:int):void{
		if(m__keyHitPut==m__keyHitQueue.length){
			return;
		}
		m__keyHit[t_key]+=1;
		m__keyHitQueue[m__keyHitPut]=t_key;
		m__keyHitPut+=1;
	}
	public function p_BeginUpdate():void{
		for(var t_i:int=0;t_i<4;t_i=t_i+1){
			var t_state:c_JoyState=m__joyStates[t_i];
			if(!BBGame.Game().PollJoystick(t_i,t_state.m_joyx,t_state.m_joyy,t_state.m_joyz,t_state.m_buttons)){
				break;
			}
			for(var t_j:int=0;t_j<32;t_j=t_j+1){
				var t_key:int=256+t_i*32+t_j;
				if(t_state.m_buttons[t_j]){
					if(!m__keyDown[t_key]){
						m__keyDown[t_key]=true;
						this.p_PutKeyHit(t_key);
					}
				}else{
					m__keyDown[t_key]=false;
				}
			}
		}
	}
	internal var m__charGet:int=0;
	internal var m__charPut:int=0;
	public function p_EndUpdate():void{
		for(var t_i:int=0;t_i<m__keyHitPut;t_i=t_i+1){
			m__keyHit[m__keyHitQueue[t_i]]=0;
		}
		m__keyHitPut=0;
		m__charGet=0;
		m__charPut=0;
	}
	internal var m__charQueue:Array=new_number_array(32);
	public function p_KeyEvent(t_event:int,t_data:int):void{
		var t_1:int=t_event;
		if(t_1==1){
			if(!m__keyDown[t_data]){
				m__keyDown[t_data]=true;
				this.p_PutKeyHit(t_data);
				if(t_data==1){
					m__keyDown[384]=true;
					this.p_PutKeyHit(384);
				}else{
					if(t_data==384){
						m__keyDown[1]=true;
						this.p_PutKeyHit(1);
					}
				}
			}
		}else{
			if(t_1==2){
				if(m__keyDown[t_data]){
					m__keyDown[t_data]=false;
					if(t_data==1){
						m__keyDown[384]=false;
					}else{
						if(t_data==384){
							m__keyDown[1]=false;
						}
					}
				}
			}else{
				if(t_1==3){
					if(m__charPut<m__charQueue.length){
						m__charQueue[m__charPut]=t_data;
						m__charPut+=1;
					}
				}
			}
		}
	}
	internal var m__mouseX:Number=.0;
	internal var m__mouseY:Number=.0;
	internal var m__touchX:Array=new_number_array(32);
	internal var m__touchY:Array=new_number_array(32);
	public function p_MouseEvent(t_event:int,t_data:int,t_x:Number,t_y:Number):void{
		var t_2:int=t_event;
		if(t_2==4){
			this.p_KeyEvent(1,1+t_data);
		}else{
			if(t_2==5){
				this.p_KeyEvent(2,1+t_data);
				return;
			}else{
				if(t_2==6){
				}else{
					return;
				}
			}
		}
		m__mouseX=t_x;
		m__mouseY=t_y;
		m__touchX[0]=t_x;
		m__touchY[0]=t_y;
	}
	public function p_TouchEvent(t_event:int,t_data:int,t_x:Number,t_y:Number):void{
		var t_3:int=t_event;
		if(t_3==7){
			this.p_KeyEvent(1,384+t_data);
		}else{
			if(t_3==8){
				this.p_KeyEvent(2,384+t_data);
				return;
			}else{
				if(t_3==9){
				}else{
					return;
				}
			}
		}
		m__touchX[t_data]=t_x;
		m__touchY[t_data]=t_y;
		if(t_data==0){
			m__mouseX=t_x;
			m__mouseY=t_y;
		}
	}
	internal var m__accelX:Number=.0;
	internal var m__accelY:Number=.0;
	internal var m__accelZ:Number=.0;
	public function p_MotionEvent(t_event:int,t_data:int,t_x:Number,t_y:Number,t_z:Number):void{
		var t_4:int=t_event;
		if(t_4==10){
		}else{
			return;
		}
		m__accelX=t_x;
		m__accelY=t_y;
		m__accelZ=t_z;
	}
	public function p_KeyHit(t_key:int):int{
		if(t_key>0 && t_key<512){
			return m__keyHit[t_key];
		}
		return 0;
	}
	public function p_KeyDown(t_key:int):Boolean{
		if(t_key>0 && t_key<512){
			return m__keyDown[t_key];
		}
		return false;
	}
	public function p_TouchX(t_index:int):Number{
		if(t_index>=0 && t_index<32){
			return m__touchX[t_index];
		}
		return 0.0;
	}
	public function p_TouchY(t_index:int):Number{
		if(t_index>=0 && t_index<32){
			return m__touchY[t_index];
		}
		return 0.0;
	}
}
class c_JoyState extends Object{
	public function m_JoyState_new():c_JoyState{
		return this;
	}
	internal var m_joyx:Array=new_number_array(2);
	internal var m_joyy:Array=new_number_array(2);
	internal var m_joyz:Array=new_number_array(2);
	internal var m_buttons:Array=new_bool_array(32);
}
var bb_input_device:c_InputDevice;
internal function bb_input_SetInputDevice(t_dev:c_InputDevice):int{
	bb_input_device=t_dev;
	return 0;
}
var bb_app2__devWidth:int;
var bb_app2__devHeight:int;
internal function bb_app2_ValidateDeviceWindow(t_notifyApp:Boolean):void{
	var t_w:int=bb_app2__game.GetDeviceWidth();
	var t_h:int=bb_app2__game.GetDeviceHeight();
	if(t_w==bb_app2__devWidth && t_h==bb_app2__devHeight){
		return;
	}
	bb_app2__devWidth=t_w;
	bb_app2__devHeight=t_h;
	if(t_notifyApp){
		bb_app2__app.p_OnResize();
	}
}
class c_DisplayMode extends Object{
	internal var m__width:int=0;
	internal var m__height:int=0;
	public function m_DisplayMode_new(t_width:int,t_height:int):c_DisplayMode{
		m__width=t_width;
		m__height=t_height;
		return this;
	}
	public function m_DisplayMode_new2():c_DisplayMode{
		return this;
	}
}
class c_Map extends Object{
	public function m_Map_new():c_Map{
		return this;
	}
	internal var m_root:c_Node=null;
	public function p_Compare(t_lhs:int,t_rhs:int):int{
		return 0;
	}
	public function p_FindNode(t_key:int):c_Node{
		var t_node:c_Node=m_root;
		while((t_node)!=null){
			var t_cmp:int=this.p_Compare(t_key,t_node.m_key);
			if(t_cmp>0){
				t_node=t_node.m_right;
			}else{
				if(t_cmp<0){
					t_node=t_node.m_left;
				}else{
					return t_node;
				}
			}
		}
		return t_node;
	}
	public function p_Contains(t_key:int):Boolean{
		return this.p_FindNode(t_key)!=null;
	}
	public function p_RotateLeft(t_node:c_Node):int{
		var t_child:c_Node=t_node.m_right;
		t_node.m_right=t_child.m_left;
		if((t_child.m_left)!=null){
			t_child.m_left.m_parent=t_node;
		}
		t_child.m_parent=t_node.m_parent;
		if((t_node.m_parent)!=null){
			if(t_node==t_node.m_parent.m_left){
				t_node.m_parent.m_left=t_child;
			}else{
				t_node.m_parent.m_right=t_child;
			}
		}else{
			m_root=t_child;
		}
		t_child.m_left=t_node;
		t_node.m_parent=t_child;
		return 0;
	}
	public function p_RotateRight(t_node:c_Node):int{
		var t_child:c_Node=t_node.m_left;
		t_node.m_left=t_child.m_right;
		if((t_child.m_right)!=null){
			t_child.m_right.m_parent=t_node;
		}
		t_child.m_parent=t_node.m_parent;
		if((t_node.m_parent)!=null){
			if(t_node==t_node.m_parent.m_right){
				t_node.m_parent.m_right=t_child;
			}else{
				t_node.m_parent.m_left=t_child;
			}
		}else{
			m_root=t_child;
		}
		t_child.m_right=t_node;
		t_node.m_parent=t_child;
		return 0;
	}
	public function p_InsertFixup(t_node:c_Node):int{
		while(((t_node.m_parent)!=null) && t_node.m_parent.m_color==-1 && ((t_node.m_parent.m_parent)!=null)){
			if(t_node.m_parent==t_node.m_parent.m_parent.m_left){
				var t_uncle:c_Node=t_node.m_parent.m_parent.m_right;
				if(((t_uncle)!=null) && t_uncle.m_color==-1){
					t_node.m_parent.m_color=1;
					t_uncle.m_color=1;
					t_uncle.m_parent.m_color=-1;
					t_node=t_uncle.m_parent;
				}else{
					if(t_node==t_node.m_parent.m_right){
						t_node=t_node.m_parent;
						this.p_RotateLeft(t_node);
					}
					t_node.m_parent.m_color=1;
					t_node.m_parent.m_parent.m_color=-1;
					this.p_RotateRight(t_node.m_parent.m_parent);
				}
			}else{
				var t_uncle2:c_Node=t_node.m_parent.m_parent.m_left;
				if(((t_uncle2)!=null) && t_uncle2.m_color==-1){
					t_node.m_parent.m_color=1;
					t_uncle2.m_color=1;
					t_uncle2.m_parent.m_color=-1;
					t_node=t_uncle2.m_parent;
				}else{
					if(t_node==t_node.m_parent.m_left){
						t_node=t_node.m_parent;
						this.p_RotateRight(t_node);
					}
					t_node.m_parent.m_color=1;
					t_node.m_parent.m_parent.m_color=-1;
					this.p_RotateLeft(t_node.m_parent.m_parent);
				}
			}
		}
		m_root.m_color=1;
		return 0;
	}
	public function p_Set(t_key:int,t_value:c_DisplayMode):Boolean{
		var t_node:c_Node=m_root;
		var t_parent:c_Node=null;
		var t_cmp:int=0;
		while((t_node)!=null){
			t_parent=t_node;
			t_cmp=this.p_Compare(t_key,t_node.m_key);
			if(t_cmp>0){
				t_node=t_node.m_right;
			}else{
				if(t_cmp<0){
					t_node=t_node.m_left;
				}else{
					t_node.m_value=t_value;
					return false;
				}
			}
		}
		t_node=(new c_Node).m_Node_new(t_key,t_value,-1,t_parent);
		if((t_parent)!=null){
			if(t_cmp>0){
				t_parent.m_right=t_node;
			}else{
				t_parent.m_left=t_node;
			}
			this.p_InsertFixup(t_node);
		}else{
			m_root=t_node;
		}
		return true;
	}
	public function p_Insert(t_key:int,t_value:c_DisplayMode):Boolean{
		return this.p_Set(t_key,t_value);
	}
}
class c_IntMap extends c_Map{
	public function m_IntMap_new():c_IntMap{
		super.m_Map_new();
		return this;
	}
	public override function p_Compare(t_lhs:int,t_rhs:int):int{
		return t_lhs-t_rhs;
	}
}
class c_Stack extends Object{
	public function m_Stack_new():c_Stack{
		return this;
	}
	internal var m_data:Array=[];
	internal var m_length:int=0;
	public function m_Stack_new2(t_data:Array):c_Stack{
		this.m_data=t_data.slice(0);
		this.m_length=t_data.length;
		return this;
	}
	public function p_Push(t_value:c_DisplayMode):void{
		if(m_length==m_data.length){
			m_data=resize_object_array(m_data,m_length*2+10);
		}
		m_data[m_length]=t_value;
		m_length+=1;
	}
	public function p_Push2(t_values:Array,t_offset:int,t_count:int):void{
		for(var t_i:int=0;t_i<t_count;t_i=t_i+1){
			this.p_Push(t_values[t_offset+t_i]);
		}
	}
	public function p_Push3(t_values:Array,t_offset:int):void{
		this.p_Push2(t_values,t_offset,t_values.length-t_offset);
	}
	public function p_ToArray():Array{
		var t_t:Array=new_object_array(m_length);
		for(var t_i:int=0;t_i<m_length;t_i=t_i+1){
			t_t[t_i]=m_data[t_i];
		}
		return t_t;
	}
}
class c_Node extends Object{
	internal var m_key:int=0;
	internal var m_right:c_Node=null;
	internal var m_left:c_Node=null;
	internal var m_value:c_DisplayMode=null;
	internal var m_color:int=0;
	internal var m_parent:c_Node=null;
	public function m_Node_new(t_key:int,t_value:c_DisplayMode,t_color:int,t_parent:c_Node):c_Node{
		this.m_key=t_key;
		this.m_value=t_value;
		this.m_color=t_color;
		this.m_parent=t_parent;
		return this;
	}
	public function m_Node_new2():c_Node{
		return this;
	}
}
var bb_app2__displayModes:Array;
var bb_app2__desktopMode:c_DisplayMode;
internal function bb_app2_DeviceWidth():int{
	return bb_app2__devWidth;
}
internal function bb_app2_DeviceHeight():int{
	return bb_app2__devHeight;
}
internal function bb_app2_EnumDisplayModes():void{
	var t_modes:Array=bb_app2__game.GetDisplayModes();
	var t_mmap:c_IntMap=(new c_IntMap).m_IntMap_new();
	var t_mstack:c_Stack=(new c_Stack).m_Stack_new();
	for(var t_i:int=0;t_i<t_modes.length;t_i=t_i+1){
		var t_w:int=t_modes[t_i].width;
		var t_h:int=t_modes[t_i].height;
		var t_size:int=t_w<<16|t_h;
		if(t_mmap.p_Contains(t_size)){
		}else{
			var t_mode:c_DisplayMode=(new c_DisplayMode).m_DisplayMode_new(t_modes[t_i].width,t_modes[t_i].height);
			t_mmap.p_Insert(t_size,t_mode);
			t_mstack.p_Push(t_mode);
		}
	}
	bb_app2__displayModes=t_mstack.p_ToArray();
	var t_mode2:BBDisplayMode=bb_app2__game.GetDesktopMode();
	if((t_mode2)!=null){
		bb_app2__desktopMode=(new c_DisplayMode).m_DisplayMode_new(t_mode2.width,t_mode2.height);
	}else{
		bb_app2__desktopMode=(new c_DisplayMode).m_DisplayMode_new(bb_app2_DeviceWidth(),bb_app2_DeviceHeight());
	}
}
var bb_graphics_renderDevice:gxtkGraphics;
internal function bb_graphics_SetMatrix(t_ix:Number,t_iy:Number,t_jx:Number,t_jy:Number,t_tx:Number,t_ty:Number):int{
	bb_graphics_context.m_ix=t_ix;
	bb_graphics_context.m_iy=t_iy;
	bb_graphics_context.m_jx=t_jx;
	bb_graphics_context.m_jy=t_jy;
	bb_graphics_context.m_tx=t_tx;
	bb_graphics_context.m_ty=t_ty;
	bb_graphics_context.m_tformed=((t_ix!=1.0 || t_iy!=0.0 || t_jx!=0.0 || t_jy!=1.0 || t_tx!=0.0 || t_ty!=0.0)?1:0);
	bb_graphics_context.m_matDirty=1;
	return 0;
}
internal function bb_graphics_SetMatrix2(t_m:Array):int{
	bb_graphics_SetMatrix(t_m[0],t_m[1],t_m[2],t_m[3],t_m[4],t_m[5]);
	return 0;
}
internal function bb_graphics_SetColor(t_r:Number,t_g:Number,t_b:Number):int{
	bb_graphics_context.m_color_r=t_r;
	bb_graphics_context.m_color_g=t_g;
	bb_graphics_context.m_color_b=t_b;
	bb_graphics_renderDevice.SetColor(t_r,t_g,t_b);
	return 0;
}
internal function bb_graphics_SetAlpha(t_alpha:Number):int{
	bb_graphics_context.m_alpha=t_alpha;
	bb_graphics_renderDevice.SetAlpha(t_alpha);
	return 0;
}
internal function bb_graphics_SetBlend(t_blend:int):int{
	bb_graphics_context.m_blend=t_blend;
	bb_graphics_renderDevice.SetBlend(t_blend);
	return 0;
}
internal function bb_graphics_SetScissor(t_x:Number,t_y:Number,t_width:Number,t_height:Number):int{
	bb_graphics_context.m_scissor_x=t_x;
	bb_graphics_context.m_scissor_y=t_y;
	bb_graphics_context.m_scissor_width=t_width;
	bb_graphics_context.m_scissor_height=t_height;
	bb_graphics_renderDevice.SetScissor(((t_x)|0),((t_y)|0),((t_width)|0),((t_height)|0));
	return 0;
}
internal function bb_graphics_BeginRender():int{
	bb_graphics_renderDevice=bb_graphics_device;
	bb_graphics_context.m_matrixSp=0;
	bb_graphics_SetMatrix(1.0,0.0,0.0,1.0,0.0,0.0);
	bb_graphics_SetColor(255.0,255.0,255.0);
	bb_graphics_SetAlpha(1.0);
	bb_graphics_SetBlend(0);
	bb_graphics_SetScissor(0.0,0.0,(bb_app2_DeviceWidth()),(bb_app2_DeviceHeight()));
	return 0;
}
internal function bb_graphics_EndRender():int{
	bb_graphics_renderDevice=null;
	return 0;
}
class c_BBGameEvent extends Object{
}
internal function bb_app2_EndApp():void{
	error("");
}
var bb_app2__updateRate:int;
internal function bb_app2_SetUpdateRate(t_hertz:int):void{
	bb_app2__updateRate=t_hertz;
	bb_app2__game.SetUpdateRate(t_hertz);
}
class c_TRender extends Object{
	public function m_TRender_new():c_TRender{
		return this;
	}
	internal static var m_shader2D:c_IShader2D;
	internal static var m_render:c_TRender;
	public function p_GraphicsInit(t_flags:int):int{
		return 0;
	}
	internal static var m_draw_list:c_List3;
	internal static var m_tris_rendered:int;
	public function p_ContextReady():Boolean{
		return false;
	}
	public function p_DeleteTexture(t_tex:c_TTexture):int{
		return 0;
	}
	public function p_BindTexture(t_tex:c_TTexture,t_flags:int):c_TTexture{
		return null;
	}
	public function p_BindTextureStack():int{
		var t_:c_Enumerator3=c_TTexture.m_tex_bind_stack.p_ObjectEnumerator();
		while(t_.p_HasNext()){
			var t_tex:c_TTexture=t_.p_NextObject();
			if(t_tex.m_bind_flags==-255){
				m_render.p_DeleteTexture(t_tex);
				t_tex.p_FreeTexture_();
			}else{
				m_render.p_BindTexture(t_tex,t_tex.m_bind_flags);
			}
			t_tex.m_bind_flags=-1;
		}
		var t_2:c_Enumerator3=c_TTexture.m_tex_bind_stack.p_ObjectEnumerator();
		while(t_2.p_HasNext()){
			var t_tex2:c_TTexture=t_2.p_NextObject();
			if(t_tex2.m_freeMemoryAfterBind){
				t_tex2.m_pixmap.p_FreePixmap();
			}
		}
		c_TTexture.m_tex_bind_stack.p_Clear();
		return 0;
	}
	public function p_Reset():void{
		return;
	}
	public function p_UpdateCamera(t_cam:c_TCamera):int{
		return 0;
	}
	public function p_UpdateLight(t_cam:c_TCamera,t_light:c_TLight):int{
		return 0;
	}
	internal static var m_render_list:c_RenderAlphaList;
	internal static var m_render_alpha_list:c_RenderAlphaList;
	internal static var m_wireframe:int;
	public function p_Render2(t_ent:c_TEntity,t_cam:c_TCamera):void{
		return;
	}
	public function p_Finish():void{
		return;
	}
	public function p_RenderCamera(t_cam:c_TCamera,t_skip:int):void{
		m_render.p_Reset();
		if(!((t_skip)!=0)){
			t_cam.p_Update2(t_cam);
			this.p_UpdateCamera(t_cam);
		}
		var t_:c_Enumerator6=c_TLight.m_light_list.p_ObjectEnumerator();
		while(t_.p_HasNext()){
			var t_light:c_TLight=t_.p_NextObject();
			this.p_UpdateLight(t_cam,t_light);
		}
		m_render_list.p_Clear();
		m_render_alpha_list.p_Clear();
		var t_mesh:c_TMesh=null;
		var t_alpha_count:int=0;
		var t_wireFrameIsEnabled:int=m_wireframe;
		var t_2:c_Enumerator7=c_TEntity.m_entity_list.p_ObjectEnumerator();
		while(t_2.p_HasNext()){
			var t_ent:c_TEntity=t_2.p_NextObject();
			t_mesh=((t_ent) as c_TMesh);
			if((t_mesh)!=null){
				if(t_mesh.p_Hidden()==true || t_mesh.m_brush.m_alpha==0.0){
					continue;
				}
				if(t_mesh.m_use_cam_layer && t_mesh.m_cam_layer!=t_cam || t_cam.m_use_cam_layer && t_mesh.m_cam_layer!=t_cam){
					continue;
				}
				t_mesh.p_GetBounds(false);
				var t_inview:Number=t_cam.p_EntityInFrustum(t_mesh);
				t_mesh.m_distance_nearplane=t_inview;
				if(t_inview>0.00001){
					t_mesh.m_culled=false;
					m_wireframe=m_wireframe|((t_mesh.m_wireframe)?1:0);
					if(t_mesh.m_auto_fade==1){
						t_mesh.p_AutoFade(t_cam);
					}
					if(((t_mesh) as c_IRenderUpdate)!=null){
						((t_mesh) as c_IRenderUpdate).p_Update2(t_cam);
					}
					if(t_mesh.p_Alpha()){
						t_mesh.m_alpha_order=t_mesh.m_distance_nearplane;
						m_render_alpha_list.p_AddLast3(t_mesh);
					}else{
						m_render.p_Render2((t_mesh),t_cam);
						m_tris_rendered+=t_mesh.m_total_tris;
					}
					m_wireframe=t_wireFrameIsEnabled;
				}
			}
		}
		m_render_alpha_list.p_Sort(1);
		var t_3:c_Enumerator9=m_render_alpha_list.p_ObjectEnumerator();
		while(t_3.p_HasNext()){
			t_mesh=t_3.p_NextObject();
			m_wireframe=m_wireframe|((t_mesh.m_wireframe)?1:0);
			m_render.p_Render2((t_mesh),t_cam);
			m_wireframe=t_wireFrameIsEnabled;
			m_tris_rendered+=t_mesh.m_total_tris;
		}
		this.p_Finish();
	}
	internal static var m_temp_shader:c_TShader;
	internal static var m_alpha_pass:int;
	internal static var m_camera2D:c_TCamera;
	internal static var m_width:int;
	internal static var m_height:int;
	public static function m_RenderDrawList():void{
		if(m_draw_list.p_IsEmpty() || !m_render.p_ContextReady()){
			return;
		}
		m_render.p_Reset();
		m_shader2D.p_SetShader2D();
		c_MojoEmulationDevice.m__quadCache.p_FlushCache();
		m_alpha_pass=1;
		var t_wireframeIsEnabled:int=m_wireframe;
		m_wireframe=0;
		m_render.p_UpdateCamera(m_camera2D);
		var t_:c_Enumerator9=m_draw_list.p_ObjectEnumerator();
		while(t_.p_HasNext()){
			var t_mesh:c_TMesh=t_.p_NextObject();
			if(!((t_mesh)!=null)){
				continue;
			}
			if(((t_mesh) as c_IRenderUpdate)!=null){
				((t_mesh) as c_IRenderUpdate).p_Update2(m_camera2D);
			}
			var t_sp:c_TSprite=((t_mesh) as c_TSprite);
			if(t_mesh.m_is_sprite){
				t_sp.m_mat_sp.p_Scale(t_sp.m_pixel_scale[0],t_sp.m_pixel_scale[1],1.0);
				t_mesh.p_EntityFX(64);
			}
			if(t_mesh.p_Alpha()){
				t_mesh.m_alpha_order=1.0;
			}
			m_render.p_Render2((t_mesh),m_camera2D);
			m_tris_rendered+=t_mesh.m_total_tris;
		}
		m_wireframe=t_wireframeIsEnabled;
		m_render.p_Finish();
		m_draw_list.p_Clear();
		m_camera2D.p_CameraClsMode(false,false);
		m_camera2D.p_CameraViewport(0,0,m_width,m_height);
		m_camera2D.p_SetPixelCamera();
	}
	public function p_RenderWorldFinish():void{
	}
	public static function m_RenderWorld():void{
		m_tris_rendered=0;
		if(m_render==null || !m_render.p_ContextReady()){
			return;
		}
		if(c_TTexture.m_tex_bind_stack.p_Length2()>0){
			m_render.p_BindTextureStack();
		}
		var t_:c_Enumerator4=c_TCamera.m_cam_list.p_ObjectEnumerator();
		while(t_.p_HasNext()){
			var t_cam:c_TCamera=t_.p_NextObject();
			if(t_cam.p_Hidden()==true){
				continue;
			}
			c_TShader.m_PreProcess(t_cam);
			if(((c_TShader.m_g_shader) as c_IShaderRender)==null){
				m_render.p_RenderCamera(t_cam,0);
			}else{
				m_temp_shader=c_TShader.m_g_shader;
				((c_TShader.m_g_shader) as c_IShaderRender).p_Render3(t_cam);
				c_TShader.m_g_shader=m_temp_shader;
			}
			c_TShader.m_PostProcess(t_cam);
		}
		m_RenderDrawList();
		m_render.p_RenderWorldFinish();
	}
	public function p_GetVersion():Number{
		return 0;
	}
	public function p_UpdateVBO(t_surface:c_TSurface):int{
		return 0;
	}
	internal static var m_vbo_enabled:Boolean;
	public function p_ClearErrors():int{
		return 1;
	}
}
interface c_IShader2D{
	function p_SetShader2D():void;
}
class c_FlashMiniB3D extends c_TRender implements c_IShader2D{
	public function m_FlashMiniB3D_new():c_FlashMiniB3D{
		super.m_TRender_new();
		c_TRender.m_shader2D=(this);
		return this;
	}
	internal static var m_driver:Driver3D;
	public function p_ForceFlashTransparency(t_g:gxtkGraphics):void{
		m_driver.ForceDeviceTransparency(t_g);
	}
	public override function p_ContextReady():Boolean{
		return m_driver.ContextReady();
	}
	internal var m_render_init:Boolean=false;
	public override function p_GetVersion():Number{
		var t_st:String="";
		var t_s:String=m_driver.CheckVersion();
		var t_num:int=0;
		for(var t_i:int=0;t_i<=t_s.length-1;t_i=t_i+1){
			if(t_s.charCodeAt(t_i)>47 && t_s.charCodeAt(t_i)<58){
				t_st=t_st+String.fromCharCode(t_s.charCodeAt(t_i));
				if(t_num==0){
					t_num=1;
				}
			}else{
				if(t_s.charCodeAt(t_i)==46 || t_s.charCodeAt(t_i)==44){
					if(t_num==2){
						break;
					}
					t_st=t_st+String.fromCharCode(t_s.charCodeAt(t_i));
					t_num=2;
				}else{
					if(t_num!=0){
						break;
					}
				}
			}
		}
		return parseFloat(t_st);
	}
	public function p_EnableStates():void{
		if(this.p_GetVersion()<11.0){
			error("You will need at least Flash 11 for this to work.");
		}
		print("..Context Success");
		m_driver.EnableErrorChecking_(false);
		m_driver.context3d.setDepthTest(true,Context3DCompareMode.LESS_EQUAL);
		m_driver.context3d.setCulling(Context3DTriangleFace.NONE);
		c_TShader.m_LoadDefaultShader2((new c_MultiShader).m_MultiShader_new());
		((c_TRender.m_render) as c_FlashMiniB3D).p_ForceFlashTransparency(bb_graphics_GetGraphicsDevice());
		m_driver.context3d.clear(0.0,0.0,0.0,0.0,1.0,0,Context3DClearMask.ALL);
		m_render_init=true;
	}
	internal static var m_last_texture:c_TTexture;
	internal static var m_last_sprite:c_TSurface;
	internal var m_last_shader:c_TShaderFlash=null;
	internal var m_last_effect:c_EffectState=(new c_EffectState).m_EffectState_new();
	public override function p_Reset():void{
		if(!m_render_init){
			this.p_EnableStates();
		}
		m_last_texture=null;
		m_last_sprite=null;
		m_last_shader=null;
		c_TRender.m_alpha_pass=0;
		m_last_effect.p_SetNull();
		m_driver.context3d.setDepthTest(true,Context3DCompareMode.LESS_EQUAL);
		c_TShader.m_DefaultShader();
	}
	internal static var m_current_cam:c_TCamera;
	internal static var m_alpha_list:c_SurfaceAlphaList;
	internal var m_surf_buf_id:int=0;
	internal var m_abuf_map:c_ArrayIntMap=(new c_ArrayIntMap).m_ArrayIntMap_new();
	internal var m_vbuf_map:c_ArrayIntMap=(new c_ArrayIntMap).m_ArrayIntMap_new();
	internal var m_ibuf_map:c_ArrayIntMap2=(new c_ArrayIntMap2).m_ArrayIntMap_new();
	public static function m_GetFlashError():int{
		return 0;
	}
	public override function p_UpdateVBO(t_surf:c_TSurface):int{
		var t_vbuffer:VertexBuffer3D=null;
		var t_ibuffer:IndexBuffer3D=null;
		var t_abuffer:VertexBuffer3D=null;
		var t_createFlag:Boolean=false;
		if(t_surf.m_reset_vbo==0 && t_surf.m_vbo_id[0]!=0){
			return 0;
		}
		var t_update:int=0;
		if(t_surf.m_vbo_id[0]==0){
			m_surf_buf_id+=1;
			if(m_surf_buf_id==0){
				m_surf_buf_id=1;
			}
			t_surf.m_vbo_id[0]=m_surf_buf_id;
			t_createFlag=true;
			t_update=1;
		}
		if(t_surf.m_reset_vbo<0){
			t_createFlag=true;
			t_surf.m_reset_vbo=255;
		}
		if(((t_surf.m_reset_vbo&1)!=0) || ((t_surf.m_reset_vbo&2)!=0) || ((t_surf.m_reset_vbo&4)!=0) || ((t_surf.m_reset_vbo&8)!=0)){
			if(t_surf.m_vbo_dyn && t_surf.m_vert_anim.length==0){
				if(t_createFlag){
					if((t_abuffer)!=null){
						t_abuffer.dispose();
					}
					t_abuffer=m_driver.context3d.createVertexBuffer(t_surf.m_no_verts,16);
					m_abuf_map.p_Set3(t_surf.m_vbo_id[0],t_abuffer);
				}else{
					t_abuffer=m_abuf_map.p_Get(t_surf.m_vbo_id[0]);
				}
				m_driver.UploadVertexFromDataBuffer(t_abuffer,t_surf.m_vert_data.m_buf,0,0,t_surf.m_no_verts);
				t_update=1;
			}
			if(t_surf.m_vbo_dyn && t_surf.m_vert_anim.length!=0){
				if(t_createFlag){
					if((t_abuffer)!=null){
						t_abuffer.dispose();
					}
					t_abuffer=m_driver.context3d.createVertexBuffer(t_surf.m_no_verts,3);
					m_abuf_map.p_Set3(t_surf.m_vbo_id[0],t_abuffer);
				}else{
					t_abuffer=m_abuf_map.p_Get(t_surf.m_vbo_id[0]);
				}
				m_driver.UploadVertexFromDataBuffer(t_abuffer,t_surf.m_vert_anim[t_surf.m_anim_frame].m_buf,0,0,t_surf.m_no_verts);
				t_update=1;
			}else{
				if(t_createFlag){
					if((t_vbuffer)!=null){
						t_vbuffer.dispose();
					}
					if((t_ibuffer)!=null){
						t_ibuffer.dispose();
					}
					t_vbuffer=m_driver.context3d.createVertexBuffer(t_surf.m_no_verts,16);
					t_ibuffer=m_driver.context3d.createIndexBuffer(t_surf.m_no_tris*3);
					m_vbuf_map.p_Set3(t_surf.m_vbo_id[0],t_vbuffer);
					m_ibuf_map.p_Set4(t_surf.m_vbo_id[0],t_ibuffer);
				}else{
					t_vbuffer=m_vbuf_map.p_Get(t_surf.m_vbo_id[0]);
				}
				m_driver.UploadVertexFromDataBuffer(t_vbuffer,t_surf.m_vert_data.m_buf,0,0,t_surf.m_no_verts);
				t_update=1;
			}
		}
		if((t_surf.m_reset_vbo&16)!=0){
			t_ibuffer=m_ibuf_map.p_Get(t_surf.m_vbo_id[0]);
			if((t_ibuffer)!=null){
				m_driver.UploadIndexFromDataBuffer(t_ibuffer,t_surf.m_tris.m_buf,0,0,t_surf.m_no_tris*3);
			}
			t_update=1;
		}
		if(false && ((m_GetFlashError())!=0)){
			print("*error: vbo update");
		}
		t_surf.m_reset_vbo=0;
		return t_update;
	}
	internal var m_effect:c_EffectState=(new c_EffectState).m_EffectState_new();
	internal var m_texdata:c_TexData=(new c_TexData).m_TexData_new();
	internal var m_shader:c_TShaderFlash=null;
	internal var m_tex_map:c_ArrayIntMap3=(new c_ArrayIntMap3).m_ArrayIntMap_new();
	internal static var m_last_tex_count:int;
	internal static var m_null_tex:c_TTexture;
	internal static var m_temp_cam:c_Matrix;
	internal static var m_temp_mat:c_Matrix;
	public override function p_Render2(t_ent:c_TEntity,t_cam:c_TCamera):void{
		m_current_cam=t_cam;
		var t_mesh:c_TMesh=((t_ent) as c_TMesh);
		if(!((t_mesh)!=null)){
			return;
		}
		var t_name:String=t_ent.p_EntityName();
		var t_fog:int=0;
		if(t_cam.m_fog_mode==1){
			t_fog=1;
		}
		var t_anim_surf2:c_TSurface=null;
		var t_ccc:int=0;
		var t_temp_list:c_List2=t_mesh.m_surf_list;
		m_alpha_list.p_Clear();
		for(var t_alphaloop:int=c_TRender.m_alpha_pass;t_alphaloop<=1;t_alphaloop=t_alphaloop+1){
			var t_:c_Enumerator8=t_temp_list.p_ObjectEnumerator();
			while(t_.p_HasNext()){
				var t_surf:c_TSurface=t_.p_NextObject();
				t_ccc+=1;
				if(t_surf.m_no_verts==0){
					continue;
				}
				if(t_surf.m_alpha_enable && t_alphaloop<1){
					m_alpha_list.p_AddLast2(t_surf);
					continue;
				}
				var t_vbo:int=1;
				var t_vbuffer:VertexBuffer3D=null;
				var t_ibuffer:IndexBuffer3D=null;
				var t_abuffer:VertexBuffer3D=null;
				this.p_UpdateVBO(t_surf);
				t_vbuffer=m_vbuf_map.p_Get(t_surf.m_vbo_id[0]);
				t_ibuffer=m_ibuf_map.p_Get(t_surf.m_vbo_id[0]);
				t_abuffer=null;
				if((t_mesh.m_anim)!=0){
					t_anim_surf2=t_mesh.p_GetAnimSurface(t_surf);
					t_mesh.p_UpdateVertexAnimFrame(t_anim_surf2,t_surf);
					if((t_anim_surf2)!=null){
						t_anim_surf2.m_vbo_dyn=true;
						this.p_UpdateVBO(t_anim_surf2);
						t_abuffer=m_abuf_map.p_Get(t_anim_surf2.m_vbo_id[0]);
					}
				}
				m_effect.p_UpdateEffect(t_surf,t_ent,t_cam);
				m_texdata.p_UpdateTexture(t_surf,t_ent);
				m_shader=((c_TShader.m_g_shader) as c_TShaderFlash);
				if(((m_shader) as c_MultiShader)!=null){
					if((m_effect.m_use_full_bright)!=0){
						if((m_texdata.m_uv_clamp)!=0){
							m_shader=((m_shader) as c_MultiShader).p_GetShader(0);
						}else{
							m_shader=((m_shader) as c_MultiShader).p_GetShader(1);
						}
					}else{
						if((m_texdata.m_uv_clamp)!=0){
							m_shader=((m_shader) as c_MultiShader).p_GetShader(2);
						}else{
							m_shader=((m_shader) as c_MultiShader).p_GetShader(3);
						}
					}
				}
				m_shader.p_Update();
				var t_skip_state:Boolean=false;
				if(m_last_sprite==t_surf){
					t_skip_state=true;
				}else{
					m_last_sprite=t_surf;
				}
				if(t_skip_state==false){
					var t_write:Boolean=true;
					if(m_effect.m_use_depth_write==0){
						t_write=false;
					}
					if(m_effect.m_use_depth_test!=m_last_effect.m_use_depth_test || m_effect.m_use_depth_write!=m_last_effect.m_use_depth_write){
						if(m_effect.m_use_depth_test==0){
							m_driver.context3d.setDepthTest(t_write,Context3DCompareMode.ALWAYS);
						}else{
							m_driver.context3d.setDepthTest(t_write,Context3DCompareMode.LESS_EQUAL);
						}
					}
					if(m_effect.m_use_backface_culling==0){
						m_driver.context3d.setCulling(Context3DTriangleFace.NONE);
					}else{
						m_driver.context3d.setCulling(Context3DTriangleFace.FRONT);
					}
					var t_1:int=m_effect.m_blend;
					if(t_1==0){
						m_driver.context3d.setBlendFactors(Context3DBlendFactor.SOURCE_ALPHA,Context3DBlendFactor.ONE_MINUS_SOURCE_ALPHA);
					}else{
						if(t_1==1){
							m_driver.context3d.setBlendFactors(Context3DBlendFactor.ONE,Context3DBlendFactor.ONE_MINUS_SOURCE_ALPHA);
						}else{
							if(t_1==2){
								m_driver.context3d.setBlendFactors(Context3DBlendFactor.DESTINATION_COLOR,Context3DBlendFactor.ZERO);
							}else{
								if(t_1==3){
									m_driver.context3d.setBlendFactors(Context3DBlendFactor.SOURCE_ALPHA,Context3DBlendFactor.ONE);
								}else{
									if(t_1==4){
										m_driver.context3d.setBlendFactors(Context3DBlendFactor.ONE,Context3DBlendFactor.ONE);
									}else{
										m_driver.context3d.setBlendFactors(Context3DBlendFactor.ONE,Context3DBlendFactor.ZERO);
									}
								}
							}
						}
					}
					if(!(t_mesh.m_anim==1 || t_surf.m_vbo_dyn==true)){
						m_driver.context3d.setVertexBufferAt(m_shader.m_u.m_vertcoords,t_vbuffer,0,Context3DVertexBufferFormat.FLOAT_3);
					}
					if(m_shader.m_u.m_normals>-1){
						m_driver.context3d.setVertexBufferAt(m_shader.m_u.m_normals,t_vbuffer,4,Context3DVertexBufferFormat.FLOAT_3);
					}
					if(m_shader.m_u.m_colors>-1){
						m_driver.context3d.setVertexBufferAt(m_shader.m_u.m_colors,t_vbuffer,8,Context3DVertexBufferFormat.FLOAT_4);
					}
				}
				if(((t_abuffer)!=null) && (((t_mesh.m_anim)!=0) || t_surf.m_vbo_dyn || ((t_anim_surf2)!=null))){
					if((t_anim_surf2.m_vert_anim).length!=0){
						m_driver.context3d.setVertexBufferAt(m_shader.m_u.m_vertcoords,t_abuffer,0,Context3DVertexBufferFormat.FLOAT_3);
					}else{
						m_driver.context3d.setVertexBufferAt(m_shader.m_u.m_vertcoords,t_abuffer,0,Context3DVertexBufferFormat.FLOAT_3);
					}
				}
				if(t_abuffer==null && t_surf.m_vbo_dyn){
					t_abuffer=m_abuf_map.p_Get(t_surf.m_vbo_id[0]);
					m_driver.context3d.setVertexBufferAt(m_shader.m_u.m_vertcoords,t_abuffer,0,Context3DVertexBufferFormat.FLOAT_3);
				}
				var t_tex_count:int=m_texdata.m_tex_count;
				for(var t_ix:int=0;t_ix<=t_tex_count-1;t_ix=t_ix+1){
					if(m_texdata.m_texture[t_ix]!=null){
						if(m_last_texture==m_texdata.m_texture[t_ix]){
						}else{
							m_last_texture=m_texdata.m_texture[t_ix];
							if(m_shader.m_u.m_texcoords0>-1){
								m_driver.context3d.setTextureAt(t_ix,m_tex_map.p_Get(m_last_texture.m_tex_id));
							}
						}
						if(!t_skip_state){
							if((m_texdata.m_tex_flags[t_ix]&8)!=0){
								if((m_texdata.m_tex_smooth[t_ix])!=0){
								}
							}else{
								if((m_texdata.m_tex_smooth[t_ix])!=0){
								}
							}
							if((m_texdata.m_tex_flags[t_ix]&16)!=0 || (m_texdata.m_tex_flags[t_ix]&32)!=0){
							}
							if(m_texdata.m_tex_coords[t_ix]==0 && m_shader.m_u.m_texcoords0>-1){
								m_driver.context3d.setVertexBufferAt(m_shader.m_u.m_texcoords0,t_vbuffer,12,Context3DVertexBufferFormat.FLOAT_2);
							}
							if(m_texdata.m_tex_coords[t_ix]==1 && m_shader.m_u.m_texcoords1>-1){
								m_driver.context3d.setVertexBufferAt(m_shader.m_u.m_texcoords1,t_vbuffer,14,Context3DVertexBufferFormat.FLOAT_2);
							}
						}
						m_driver.UploadConstantsFromArray(Context3DProgramType.VERTEX,m_shader.m_u.m_tex_position[t_ix],[m_texdata.m_tex_u_pos[t_ix],m_texdata.m_tex_v_pos[t_ix],Math.cos((m_texdata.m_tex_ang[t_ix])*D2R),Math.sin((m_texdata.m_tex_ang[t_ix])*D2R)],0);
						m_driver.UploadConstantsFromArray(Context3DProgramType.VERTEX,m_shader.m_u.m_tex_scale[t_ix],[m_texdata.m_tex_u_scale[t_ix],m_texdata.m_tex_v_scale[t_ix],0.0,0.0],0);
						if((m_texdata.m_tex_flags[t_ix]&128)!=0){
						}
					}
				}
				if(m_texdata.m_tex_count==0 && (m_shader.m_u.m_texcoords0>-1 || m_shader.m_u.m_texcoords1>-1)){
					for(var t_ix2:int=0;t_ix2<=m_last_tex_count-1;t_ix2=t_ix2+1){
						m_driver.context3d.setTextureAt(t_ix2,null);
					}
					m_last_texture=null;
					m_driver.context3d.setTextureAt(0,m_tex_map.p_Get(m_null_tex.m_tex_id));
					if(m_shader.m_u.m_texcoords0>-1){
						m_driver.context3d.setVertexBufferAt(m_shader.m_u.m_texcoords0,t_vbuffer,12,Context3DVertexBufferFormat.FLOAT_2);
					}
					if(m_shader.m_u.m_texcoords1>-1){
						m_driver.context3d.setVertexBufferAt(m_shader.m_u.m_texcoords1,t_vbuffer,20,Context3DVertexBufferFormat.FLOAT_2);
					}
				}
				m_last_tex_count=m_texdata.m_tex_count;
				m_temp_cam.p_Overwrite(t_cam.m_projview_mat);
				if(t_mesh.m_is_sprite==false){
					m_temp_cam.p_Multiply4(t_ent.m_mat);
					m_driver.UploadConstantsFromArray(Context3DProgramType.VERTEX,m_shader.m_u.m_m_matrix,bb_flash11_AGALMatrix(t_ent.m_mat),0);
					m_temp_mat.p_Overwrite(t_ent.m_mat);
					m_driver.UploadConstantsFromArray(Context3DProgramType.VERTEX,m_shader.m_u.m_n_matrix,bb_flash11_AGALMatrix(m_temp_mat.p_Inverse().p_Transpose()),0);
				}else{
					m_temp_cam.p_Multiply4(((t_mesh) as c_TSprite).m_mat_sp);
					m_driver.UploadConstantsFromArray(Context3DProgramType.VERTEX,m_shader.m_u.m_m_matrix,bb_flash11_AGALMatrix(((t_mesh) as c_TSprite).m_mat_sp),0);
					m_temp_mat.p_Overwrite(((t_mesh) as c_TSprite).m_mat_sp);
					m_driver.UploadConstantsFromArray(Context3DProgramType.VERTEX,m_shader.m_u.m_n_matrix,bb_flash11_AGALMatrix(m_temp_mat.p_Inverse().p_Transpose()),0);
				}
				m_driver.UploadConstantsFromArray(Context3DProgramType.VERTEX,m_shader.m_u.m_p_matrix,bb_flash11_AGALMatrix(m_temp_cam),0);
				if(m_shader.m_u.m_light_matrix[0]>-1 && c_TLight.m_light_list.p_IsEmpty()==false && m_effect.m_use_full_bright==0){
					var t_ll:c_TLight=c_TLight.m_light_list.p_First();
					m_temp_mat.p_Overwrite(t_ll.m_mat);
					if(t_ll.m_light_type==1){
						m_temp_mat.m_grid[3][0]=0.0;
						m_temp_mat.m_grid[3][1]=0.0;
						m_temp_mat.m_grid[3][2]=1.0;
						m_driver.UploadConstantsFromArray(Context3DProgramType.VERTEX,m_shader.m_u.m_lightflag,[1.0,0.0,0.0,0.0],0);
					}else{
						if(t_ll.m_light_type==2){
							m_driver.UploadConstantsFromArray(Context3DProgramType.VERTEX,m_shader.m_u.m_lightflag,[0.0,1.0,0.0,0.0],0);
						}
						if(t_ll.m_light_type==3){
							m_driver.UploadConstantsFromArray(Context3DProgramType.VERTEX,m_shader.m_u.m_lightflag,[0.0,0.0,1.0,0.0],0);
						}
					}
					m_driver.UploadConstantsFromArray(Context3DProgramType.VERTEX,m_shader.m_u.m_light_matrix[0],bb_flash11_AGALMatrix(m_temp_mat),0);
					m_driver.UploadConstantsFromArray(Context3DProgramType.VERTEX,m_shader.m_u.m_light_color[0],[t_ll.m_red,t_ll.m_green,t_ll.m_blue,1.0],0);
					m_driver.UploadConstantsFromArray(Context3DProgramType.VERTEX,m_shader.m_u.m_light_att[0],[t_ll.m_const_att,t_ll.m_lin_att,t_ll.m_quad_att,t_ll.m_actual_range],0);
				}else{
					m_driver.UploadConstantsFromArray(Context3DProgramType.VERTEX,m_shader.m_u.m_light_color[0],[1.0,1.0,1.0,1.0],0);
				}
				m_driver.UploadConstantsFromArray(Context3DProgramType.VERTEX,m_shader.m_u.m_colorflag,[1.0-(m_effect.m_use_vertex_colors),0.0,0.0,0.0],0);
				m_driver.UploadConstantsFromArray(Context3DProgramType.VERTEX,m_shader.m_u.m_base_color,m_effect.m_diffuse,0);
				m_driver.UploadConstantsFromArray(Context3DProgramType.VERTEX,m_shader.m_u.m_ambient_color,m_effect.m_ambient,0);
				m_driver.UploadConstantsFromArray(Context3DProgramType.VERTEX,m_shader.m_u.m_miscflag,[0.5*(m_effect.m_use_alpha_test),0.0,0.0,0.0],0);
				m_driver.UploadConstantsFromArray(Context3DProgramType.FRAGMENT,m_shader.m_u.m_miscflag,[0.5*(m_effect.m_use_alpha_test),0.0,0.0,0.0],0);
				if(m_shader!=m_last_shader){
					m_driver.context3d.setProgram(m_shader.m_program_set);
					m_last_shader=m_shader;
				}
				if((c_TRender.m_wireframe)!=0){
				}else{
					if((t_vbo)!=0){
						try{
							m_driver.context3d.drawTriangles(t_ibuffer,0,t_surf.m_no_tris);
						}catch(t_e:Error){
							print("**"+t_e.toString());
						}
					}
				}
				m_last_effect.p_Overwrite2(m_effect);
			}
			if(!((m_alpha_list)!=null)){
				break;
			}
			t_temp_list=(m_alpha_list);
		}
		t_temp_list=null;
	}
	public override function p_Finish():void{
	}
	public override function p_RenderWorldFinish():void{
		m_driver.PresentToDevice(null);
		m_driver.context3d.clear(0.0,0.0,0.0,0.0,1.0,0,Context3DClearMask.ALL);
	}
	public override function p_GraphicsInit(t_flags:int):int{
		c_TRender.m_render=((new c_FlashMiniB3D).m_FlashMiniB3D_new());
		c_TRender.m_width=bb_app2_DeviceWidth();
		c_TRender.m_height=bb_app2_DeviceHeight();
		m_driver.InitContext(c_TRender.m_width,c_TRender.m_height,0,0);
		c_TTexture.m_TextureFilter("",9);
		c_TPixmapFlash.m_Init();
		m_null_tex=bb_functions_CreateTexture(1,1,2,1);
		c_TexData.m_null_tex=m_null_tex;
		c_TRender.m_vbo_enabled=true;
		c_TEntity.m_global_mat.p_LoadIdentity();
		return 1;
	}
	public override function p_DeleteTexture(t_tex:c_TTexture):int{
		return 0;
	}
	internal var m_tex_map_id:int=0;
	public override function p_BindTexture(t_tex:c_TTexture,t_flags:int):c_TTexture{
		c_TRender.m_render.p_ClearErrors();
		if((t_flags&4)!=0){
		}
		var t_width:int=t_tex.m_pixmap.m_width;
		var t_height:int=t_tex.m_pixmap.m_height;
		var t_ftex:Texture=null;
		if(((t_tex.m_pixmap.m_bind)!=0) && ((t_tex.m_tex_id)!=0)){
			return t_tex;
		}
		if(t_width==0 || t_height==0){
			return t_tex;
		}
		if(!((t_tex.m_tex_id)!=0)){
			m_tex_map_id+=1;
			t_tex.m_tex_id=m_tex_map_id;
			t_ftex=m_driver.context3d.createTexture(t_width,t_height,Context3DTextureFormat.BGRA,false);
			m_tex_map.p_Set5(t_tex.m_tex_id,t_ftex);
		}
		var t_mipmap:int=0;
		var t_mip_level:int=0;
		var t_pix:c_TPixmapFlash=((t_tex.m_pixmap) as c_TPixmapFlash);
		if((t_flags&8)!=0){
			t_mipmap=1;
		}
		do{
			var t_uploaded:int=m_driver.UploadTextureData(t_ftex,t_pix.m_pixels,t_mip_level);
			if(!((t_uploaded)!=0)){
				error("** out of texture memory or no data **");
			}
			if(!((t_mipmap)!=0) || t_width==1 && t_height==1){
				break;
			}
			if(t_width>1){
				t_width=(((t_width)*0.5)|0);
			}
			if(t_height>1){
				t_height=(((t_height)*0.5)|0);
			}
			if(t_tex.m_resize_smooth){
				t_pix=((t_pix.p_ResizePixmap(t_width,t_height)) as c_TPixmapFlash);
			}else{
				t_pix=((t_pix.p_ResizePixmapNoSmooth(t_width,t_height)) as c_TPixmapFlash);
			}
			t_mip_level+=1;
		}while(!(false));
		t_tex.m_no_mipmaps=t_mip_level;
		t_tex.m_pixmap.p_SetBind();
		return t_tex;
	}
	public override function p_UpdateLight(t_cam:c_TCamera,t_light:c_TLight):int{
		return 0;
	}
	internal static var m_fastQuad:c_TMesh;
	internal static var m_shader2d_:c_TShaderFlash;
	public function p_SetShader2D():void{
		if(!((m_shader2d_)!=null)){
		}
		m_shader2d_=((c_TShader.m_DefaultShader()) as c_TShaderFlash);
	}
	public function p_DrawClearQuad(t_cam:c_TCamera,t_r:Number,t_g:Number,t_b:Number):void{
		if(m_fastQuad==null){
			m_fastQuad=(bb_functions_CreateSprite(null));
			m_fastQuad.p_RemoveFromRenderList();
			m_fastQuad.p_ScaleEntity((c_TRender.m_width),(c_TRender.m_height),1.0,0);
			m_fastQuad.p_PositionEntity(0.0,0.0,1.99999,0);
			m_fastQuad.p_EntityFX(105);
			m_fastQuad.m_classname="fastQuad";
			((m_fastQuad) as c_IRenderUpdate).p_Update2(c_TRender.m_camera2D);
		}
		c_TRender.m_render.p_Reset();
		this.p_SetShader2D();
		m_fastQuad.p_EntityColorFloat(t_r,t_g,t_b,-1.0);
		c_TRender.m_alpha_pass=1;
		var t_wireframeIsEnabled:int=c_TRender.m_wireframe;
		c_TRender.m_wireframe=0;
		m_driver.context3d.setColorMask(true,true,true,true);
		c_TRender.m_render.p_Render2((m_fastQuad),c_TRender.m_camera2D);
		m_driver.context3d.setColorMask(true,true,true,true);
		c_TRender.m_wireframe=t_wireframeIsEnabled;
		c_TRender.m_render.p_Finish();
		c_TRender.m_render.p_Reset();
	}
	public override function p_UpdateCamera(t_cam:c_TCamera):int{
		if(t_cam.p_Hidden()){
			return 0;
		}
		m_driver.SetScissorRectangle_(t_cam.m_vx,-(t_cam.m_vy-c_TRender.m_height+t_cam.m_vheight),t_cam.m_vwidth,t_cam.m_vheight);
		if(t_cam.m_cls_color==true && t_cam.m_cls_zbuffer==true){
			m_driver.context3d.clear(t_cam.m_cls_r,t_cam.m_cls_g,t_cam.m_cls_b,0.0,1.0,0,Context3DClearMask.DEPTH);
			this.p_DrawClearQuad(t_cam,t_cam.m_cls_r,t_cam.m_cls_g,t_cam.m_cls_b);
		}else{
			if(t_cam.m_cls_color==true){
				this.p_DrawClearQuad(t_cam,t_cam.m_cls_r,t_cam.m_cls_g,t_cam.m_cls_b);
			}else{
				if(t_cam.m_cls_zbuffer==true){
					m_driver.context3d.clear(t_cam.m_cls_r,t_cam.m_cls_g,t_cam.m_cls_b,0.0,1.0,0,Context3DClearMask.DEPTH);
				}
			}
		}
		if(t_cam.m_fog_mode>0){
		}
		return 0;
	}
	public override function p_ClearErrors():int{
		return 0;
	}
}
class c_BlankShader extends Object implements c_IShader2D{
	public function m_BlankShader_new():c_BlankShader{
		return this;
	}
	public function p_SetShader2D():void{
	}
}
class c_MojoEmulationDevice extends gxtkGraphics{
	internal static var m__device:c_MojoEmulationDevice;
	internal static var m__olddevice:gxtkGraphics;
	public function m_MojoEmulationDevice_new():c_MojoEmulationDevice{
		return this;
	}
	internal static var m__quadCache:c_QuadCache;
	internal var m_mesh:c_TMesh=null;
	internal var m_layer:int=0;
	internal var m_solid:Array=new_object_array(512);
	public function p_NewLayer():void{
		if(m_mesh==null){
			return;
		}
		m_layer+=1;
		if(m_layer>512){
			m_layer=0;
		}
		if(!((m_solid[m_layer])!=null)){
			m_solid[m_layer]=m_mesh.p_CreateSurface(null);
		}else{
			m_mesh.p_AddSurface(m_solid[m_layer]);
		}
		m_solid[m_layer].m_no_verts=0;
		m_solid[m_layer].m_no_tris=0;
		m_solid[m_layer].m_vbo_dyn=true;
		m_solid[m_layer].m_brush.m_fx=35;
		m_mesh.m_brush.m_blend=0;
	}
	internal var m_lastBlend:int=-1;
	internal var m_lastSurface:c_MojoSurface=null;
	internal var m_mat:c_Matrix=(new c_Matrix).m_Matrix_new();
	public function p_Reset():int{
		if(!((m_mesh)!=null)){
			m_mesh=bb_functions_CreateMesh(null);
			m_mesh.m_entity_link.p_Remove();
			m_mesh.p_EntityFX(67);
			m_layer=-1;
			this.p_NewLayer();
		}
		m_mesh.m_no_surfs=1;
		m_mesh.m_surf_list.p_Clear();
		m_mesh.m_surf_list.p_AddLast2(m_solid[0]);
		m_solid[0].m_no_verts=0;
		m_solid[0].m_no_tris=0;
		m_layer=0;
		m_lastBlend=0;
		m_lastSurface=null;
		c_TRender.m_draw_list.p_AddLast3(m_mesh);
		m_mat.p_LoadIdentity();
		return 0;
	}
	internal static var m_firstTimeRun:Boolean;
	internal var m_fontImage:c_Image=null;
	internal var m_fontFile:String="mojo_font.png";
	public function p_InitFont():void{
		if(((m_fontImage)!=null) && m_fontImage.p_Width()>0){
			return;
		}
		m_fontImage=bb_graphics_LoadImage(m_fontFile,96,2);
		if(((m_fontImage)!=null) && m_fontImage.p_Width()>0){
			bb_graphics_SetFont(m_fontImage,32);
		}
	}
	public static function m_SetDevice():void{
		if(!((m__device)!=null)){
			m__olddevice=bb_graphics_GetGraphicsDevice();
			m__device=(new c_MojoEmulationDevice).m_MojoEmulationDevice_new();
			m__quadCache=(new c_QuadCache).m_QuadCache_new();
			((c_TRender.m_render) as c_FlashMiniB3D).p_ForceFlashTransparency(m__olddevice);
			((c_TRender.m_render) as c_FlashMiniB3D).p_ForceFlashTransparency(m__device);
		}
		m__device.p_Reset();
		bb_graphics_SetGraphicsDevice(m__device);
		bb_graphics_BeginRender();
		if(m_firstTimeRun){
			m__device.p_InitFont();
		}else{
			bb_functions_PreLoadPixmap2(m__device.m_fontFile);
		}
		m_firstTimeRun=true;
	}
	public override function Width():int{
		return c_TRender.m_width;
	}
	public override function Height():int{
		return c_TRender.m_height;
	}
	public override function LoadSurface(t_path:String):gxtkSurface{
		var t_msurf:c_MojoSurface=c_MojoSurface.m_PreLoad(t_path,m_mesh,m__device);
		return ((t_msurf) as gxtkSurface);
	}
	public override function CreateSurface(t_width:int,t_height:int):gxtkSurface{
		var t_msurf:c_MojoSurface=c_MojoSurface.m_Create("");
		return ((t_msurf) as gxtkSurface);
	}
	public override function WritePixels2(t_surface:gxtkSurface,t_pixels:Array,t_x:int,t_y:int,t_width:int,t_height:int,t_offset:int,t_pitch:int):int{
		return 0;
	}
	public override function Cls(t_r:Number,t_g:Number,t_b:Number):int{
		c_TRender.m_camera2D.p_CameraClsColor(t_r,t_g,t_b);
		c_TRender.m_camera2D.p_CameraClsMode(true,false);
		return 0;
	}
	internal var m_colora:Number=1.0;
	public override function SetAlpha(t_alpha:Number):int{
		m_colora=t_alpha;
		return 0;
	}
	internal var m_colorr:int=0;
	internal var m_colorg:int=0;
	internal var m_colorb:int=0;
	public override function SetColor(t_r:Number,t_g:Number,t_b:Number):int{
		m_colorr=((t_r)|0);
		m_colorg=((t_g)|0);
		m_colorb=((t_b)|0);
		return 0;
	}
	public override function SetMatrix(t_ix:Number,t_iy:Number,t_jx:Number,t_jy:Number,t_tx:Number,t_ty:Number):int{
		m_mat.m_grid[0][0]=t_ix;
		m_mat.m_grid[1][0]=t_iy;
		m_mat.m_grid[0][1]=t_jx;
		m_mat.m_grid[1][1]=t_jy;
		m_mat.m_grid[3][0]=t_tx;
		m_mat.m_grid[3][1]=-t_ty;
		return 0;
	}
	public override function SetScissor(t_x:int,t_y:int,t_width:int,t_height:int):int{
		c_TRender.m_camera2D.p_CameraScissor(t_x,t_y,t_width,t_height);
		return 0;
	}
	public override function SetBlend(t_blend:int):int{
		if(t_blend!=m_lastBlend){
			this.p_NewLayer();
		}
		if(t_blend==1){
			m_solid[m_layer].m_brush.m_blend=3;
		}else{
			if(t_blend==1){
				m_solid[m_layer].m_brush.m_blend=4;
			}else{
				m_solid[m_layer].m_brush.m_blend=1;
			}
		}
		m_lastBlend=t_blend;
		return 0;
	}
	public function p_Check(t_s:c_MojoSurface):int{
		if(t_s!=m_lastSurface){
			this.p_NewLayer();
			m_lastSurface=t_s;
		}
		return 0;
	}
	internal var m_zdepth:Number=1.99999;
	public function p_AddQuad(t_s:c_TSurface,t_x:Number,t_y:Number,t_w:Number,t_h:Number,t_u:Number,t_v:Number,t_uw:Number,t_vh:Number):void{
		var t_p0:Array=[];
		var t_p1:Array=[];
		var t_p2:Array=[];
		var t_p3:Array=[];
		var t_r:Number=.0;
		var t_g:Number=.0;
		var t_b:Number=.0;
		t_p0=bb_mojographics_Transform2D(m_mat,t_x,-t_h-t_y,m_zdepth);
		t_p1=bb_mojographics_Transform2D(m_mat,t_x,-t_y,m_zdepth);
		t_p2=bb_mojographics_Transform2D(m_mat,t_x+t_w,-t_y,m_zdepth);
		t_p3=bb_mojographics_Transform2D(m_mat,t_x+t_w,-t_h-t_y,m_zdepth);
		t_r=(m_colorr)*0.0039215686274509803;
		t_g=(m_colorg)*0.0039215686274509803;
		t_b=(m_colorb)*0.0039215686274509803;
		m__quadCache.p_AddCache(t_s,[t_p0[0],t_p0[1],-t_p0[2],0.0,1.0,1.0,1.0,0.0,t_r,t_g,t_b,m_colora,t_u,t_vh,t_u,t_vh,t_p1[0],t_p1[1],-t_p1[2],0.0,1.0,1.0,1.0,0.0,t_r,t_g,t_b,m_colora,t_u,t_v,t_u,t_v,t_p2[0],t_p2[1],-t_p2[2],0.0,1.0,1.0,1.0,0.0,t_r,t_g,t_b,m_colora,t_uw,t_v,t_uw,t_v,t_p3[0],t_p3[1],-t_p3[2],0.0,1.0,1.0,1.0,0.0,t_r,t_g,t_b,m_colora,t_uw,t_vh,t_uw,t_vh]);
		t_s.m_reset_vbo=-1;
	}
	public override function DrawPoint(t_x:Number,t_y:Number):int{
		this.p_Check(null);
		this.p_AddQuad(m_solid[m_layer],t_x,t_y,1.0,1.0,0.0,0.0,1.0,1.0);
		return 0;
	}
	public override function DrawRect(t_x:Number,t_y:Number,t_w:Number,t_h:Number):int{
		this.p_Check(null);
		this.p_AddQuad(m_solid[m_layer],t_x,t_y,t_w,t_h,0.0,0.0,1.0,1.0);
		return 0;
	}
	public override function DrawLine(t_x1:Number,t_y1:Number,t_x2:Number,t_y2:Number):int{
		this.p_Check(null);
		var t_p0:Array=[];
		t_p0=bb_mojographics_Transform2D(m_mat,t_x1,-t_y1,m_zdepth);
		t_x1=t_p0[0];
		t_y1=t_p0[1];
		t_p0=bb_mojographics_Transform2D(m_mat,t_x2,-t_y2,m_zdepth);
		t_x2=t_p0[0];
		t_y2=t_p0[1];
		var t_px:Number=t_y1-t_y2;
		var t_py:Number=-(t_x1-t_x2);
		var t_d:Number=1.0/Math.sqrt(t_px*t_px+t_py*t_py);
		t_px=t_px*t_d;
		t_py=t_py*t_d;
		var t_v0:int=m_solid[m_layer].p_AddVertex(t_x2,t_y2,m_zdepth,0.0,1.0,0.0);
		var t_v1:int=m_solid[m_layer].p_AddVertex(t_x1,t_y1,m_zdepth,0.0,0.0,0.0);
		var t_v2:int=m_solid[m_layer].p_AddVertex(t_x1+t_px,t_y1+t_py,m_zdepth,1.0,0.0,0.0);
		m_solid[m_layer].p_AddTriangle(t_v0,t_v1,t_v2);
		var t_v3:int=m_solid[m_layer].p_AddVertex(t_x2+t_px,t_y2+t_py,m_zdepth,1.0,0.0,0.0);
		m_solid[m_layer].p_AddTriangle(t_v0,t_v2,t_v3);
		m_solid[m_layer].p_VertexColor(t_v0,(m_colorr),(m_colorg),(m_colorb),m_colora);
		m_solid[m_layer].p_VertexColor(t_v1,(m_colorr),(m_colorg),(m_colorb),m_colora);
		m_solid[m_layer].p_VertexColor(t_v2,(m_colorr),(m_colorg),(m_colorb),m_colora);
		m_solid[m_layer].p_VertexColor(t_v3,(m_colorr),(m_colorg),(m_colorb),m_colora);
		m_solid[m_layer].m_reset_vbo=-1;
		return 0;
	}
	public override function DrawPoly(t_verts:Array):int{
		this.p_Check(null);
		var t_p0:Array=[];
		var t_p1:Array=[];
		var t_p2:Array=[];
		var t_p3:Array=[];
		var t_r:Number=.0;
		var t_g:Number=.0;
		var t_b:Number=.0;
		var t_tris:Array=new_number_array((t_verts.length-7)*6*3);
		var t_t:int=0;
		var t_vt:int=m_solid[m_layer].m_no_verts;
		t_r=(m_colorr)*0.0039215686274509803;
		t_g=(m_colorg)*0.0039215686274509803;
		t_b=(m_colorb)*0.0039215686274509803;
		for(var t_i:int=0;t_i<=t_verts.length-7;t_i=t_i+6){
			t_p0=bb_mojographics_Transform2D(m_mat,t_verts[t_i+0],-t_verts[t_i+1],m_zdepth);
			t_p1=bb_mojographics_Transform2D(m_mat,t_verts[t_i+2],-t_verts[t_i+3],m_zdepth);
			t_p2=bb_mojographics_Transform2D(m_mat,t_verts[t_i+4],-t_verts[t_i+5],m_zdepth);
			t_vt=t_vt+3;
			m_solid[m_layer].p_AddVertex2([t_p0[0],t_p0[1],-t_p0[2],0.0,1.0,1.0,1.0,0.0,(m_colorr)*0.0039215686274509803,(m_colorg)*0.0039215686274509803,(m_colorb)*0.0039215686274509803,m_colora,0.0,0.0,0.0,0.0,t_p1[0],t_p1[1],-t_p1[2],0.0,1.0,1.0,1.0,0.0,(m_colorr)*0.0039215686274509803,(m_colorg)*0.0039215686274509803,(m_colorb)*0.0039215686274509803,m_colora,0.0,0.0,0.0,0.0,t_p2[0],t_p2[1],-t_p2[2],0.0,1.0,1.0,1.0,0.0,(m_colorr)*0.0039215686274509803,(m_colorg)*0.0039215686274509803,(m_colorb)*0.0039215686274509803,m_colora,0.0,0.0,0.0,0.0],-1);
			t_tris[t_t]=t_vt-3;
			t_tris[t_t+1]=t_vt-2;
			t_tris[t_t+2]=t_vt-1;
			t_t=t_t+3;
		}
		m_solid[m_layer].p_AddTriangle2(t_tris,-1);
		return 0;
	}
	public override function DrawOval(t_x:Number,t_y:Number,t_w:Number,t_h:Number):int{
		this.p_Check(null);
		if(t_w<0.0){
			t_w=-t_w;
		}
		if(t_h<0.0){
			t_h=-t_h;
		}
		var t_seg:int=(((t_w+t_h)*0.2)|0);
		if(t_seg<14){
			t_seg=14;
		}
		var t_deg:Number=0.0;
		var t_deginc:Number=360.0/(t_seg);
		var t_verts:Array=new_number_array(t_seg*6+1);
		for(var t_i:int=0;t_i<=t_verts.length-7;t_i=t_i+6){
			t_verts[t_i+0]=t_x;
			t_verts[t_i+1]=t_y;
			t_verts[t_i+2]=t_x+t_w*Math.cos((t_deg)*D2R);
			t_verts[t_i+3]=t_y+t_h*Math.sin((t_deg)*D2R);
			t_verts[t_i+4]=t_x+t_w*Math.cos((t_deg+t_deginc)*D2R);
			t_verts[t_i+5]=t_y+t_h*Math.sin((t_deg+t_deginc)*D2R);
			t_deg+=t_deginc;
		}
		this.DrawPoly(t_verts);
		return 0;
	}
	public override function DrawSurface2(t_surface:gxtkSurface,t_x:Number,t_y:Number,t_srcx:int,t_srcy:int,t_srcw:int,t_srch:int):int{
		var t_s:c_MojoSurface=((t_surface) as c_MojoSurface);
		if(!((t_s)!=null)){
			return 0;
		}
		this.p_Check(t_s);
		if((t_s.m_tex)!=null){
			m_solid[m_layer].p_PaintSurface2(t_s.m_tex,0);
		}
		var t_xstep:Number=t_s.m_xstep;
		var t_ystep:Number=t_s.m_ystep;
		var t_upos:Number=(t_srcx)*t_xstep;
		var t_vpos:Number=(t_srcy)*t_ystep;
		this.p_AddQuad(m_solid[m_layer],t_x,t_y,(t_srcw),(t_srch),t_upos,t_vpos,t_upos+t_xstep*(t_srcw),t_vpos+t_ystep*(t_srch));
		return 0;
	}
	public override function DrawSurface(t_surface:gxtkSurface,t_x:Number,t_y:Number):int{
		this.DrawSurface2(t_surface,t_x,t_y,0,0,t_surface.Width(),t_surface.Height());
		return 0;
	}
	public override function ReadPixels(t_pixels:Array,t_x:int,t_y:int,t_width:int,t_height:int,t_offset:int,t_pitch:int):int{
		return 0;
	}
}
internal function bb_graphics_GetGraphicsDevice():gxtkGraphics{
	return bb_graphics_device;
}
class c_QuadCache extends Object{
	public function m_QuadCache_new():c_QuadCache{
		return this;
	}
	internal var m_q_num:int=0;
	internal var m_q_cache:Array=new_number_array(1280);
	internal var m_q_surf:c_TSurface=null;
	internal var m_q_tri:Array=new_number_array(128);
	public function p_FlushCache():void{
		if(m_q_num==0){
			return;
		}
		var t_n:int=m_q_num;
		var t_v4:int=m_q_surf.p_AddVertex2(m_q_cache,m_q_num*64);
		t_v4=t_v4+1-m_q_num*4;
		var t_k:int=0;
		for(var t_j:int=0;t_j<=t_n-1;t_j=t_j+1){
			m_q_tri[t_k+0]=t_v4;
			m_q_tri[t_k+1]=t_v4+1;
			m_q_tri[t_k+2]=t_v4+2;
			m_q_tri[t_k+3]=t_v4;
			m_q_tri[t_k+4]=t_v4+2;
			m_q_tri[t_k+5]=t_v4+3;
			t_k=t_k+6;
			t_v4=t_v4+4;
		}
		m_q_surf.p_AddTriangle2(m_q_tri,m_q_num*6);
		m_q_num=0;
		m_q_surf=null;
	}
	public function p_AddCache(t_s:c_TSurface,t_v:Array):void{
		if(t_s!=m_q_surf || m_q_num>19){
			this.p_FlushCache();
		}
		m_q_surf=t_s;
		var t_offset:int=m_q_num*64;
		for(var t_i:int=0;t_i<=63;t_i=t_i+1){
			m_q_cache[t_offset+t_i]=t_v[t_i];
		}
		m_q_num+=1;
	}
}
class c_TEntity extends Object{
	internal var m_mat:c_Matrix=(new c_Matrix).m_Matrix_new();
	internal var m_loc_mat:c_Matrix=(new c_Matrix).m_Matrix_new();
	public function m_TEntity_new():c_TEntity{
		m_mat.p_LoadIdentity();
		m_loc_mat.p_LoadIdentity();
		return this;
	}
	internal var m_classname:String="";
	internal var m_parent:c_TEntity=null;
	internal var m_px:Number=.0;
	internal var m_py:Number=.0;
	internal var m_pz:Number=.0;
	internal var m_rx:Number=.0;
	internal var m_ry:Number=.0;
	internal var m_rz:Number=.0;
	internal var m_sx:Number=1.0;
	internal var m_sy:Number=1.0;
	internal var m_sz:Number=1.0;
	internal var m_gsx:Number=1.0;
	internal var m_gsy:Number=1.0;
	internal var m_gsz:Number=1.0;
	internal var m_collision:c_TCollision=(new c_TCollision).m_TCollision_new();
	public function p_UpdateMat(t_load_identity:Boolean):void{
		if(t_load_identity==true){
			m_mat.p_LoadIdentity();
		}
		if(t_load_identity==false && ((m_parent)!=null)){
			m_mat.p_Overwrite(m_parent.m_mat);
		}
		m_mat.p_Translate(m_px,m_py,m_pz);
		m_mat.p_Rotate(m_rx,m_ry,m_rz);
		m_mat.p_Scale(m_sx,m_sy,m_sz);
		if(t_load_identity){
			m_loc_mat.p_Overwrite(m_mat);
		}
		if((m_parent)!=null){
			m_gsx=m_parent.m_gsx*m_sx;
			m_gsy=m_parent.m_gsy*m_sy;
			m_gsz=m_parent.m_gsz*m_sz;
		}else{
			m_gsx=m_sx;
			m_gsy=m_sy;
			m_gsz=m_sz;
		}
		m_collision.m_updated_shape=false;
	}
	internal var m_child_list:c_EntityList=(new c_EntityList).m_EntityList_new();
	internal var m_parent_link:c_Node2=null;
	public function p_AddParent(t_parent_ent:c_TEntity):int{
		m_parent=t_parent_ent;
		if(m_parent!=null){
			m_mat.p_Overwrite(m_parent.m_mat);
			this.p_UpdateMat(false);
			m_parent_link=m_parent.m_child_list.p_AddLast(this);
		}
		return 0;
	}
	internal static var m_entity_list:c_EntityList;
	internal var m_order:int=0;
	internal var m_entity_link:c_Node2=null;
	internal var m_brush:c_TBrush=(new c_TBrush).m_TBrush_new();
	public function p_EntityFX(t_fx_no:int):c_TEntity{
		m_brush.m_fx=t_fx_no;
		return this;
	}
	public function p_EntityFX2():int{
		return m_brush.m_fx;
	}
	internal var m_hide:Boolean=false;
	public function p_Hidden():Boolean{
		return m_hide;
	}
	internal var m_name:String="";
	internal var m_use_cam_layer:Boolean=false;
	internal var m_cam_layer:c_TCamera=null;
	internal var m_cull_radius:Number=.0;
	public function p_EntityX(t_glob:int):Number{
		if(t_glob==0){
			return m_px;
		}else{
			return m_mat.m_grid[3][0];
		}
		return 0;
	}
	public function p_EntityY(t_glob:int):Number{
		if(t_glob==0){
			return m_py;
		}else{
			return m_mat.m_grid[3][1];
		}
		return 0;
	}
	public function p_EntityZ(t_glob:int):Number{
		if(t_glob==0){
			return -m_pz;
		}else{
			return -m_mat.m_grid[3][2];
		}
		return 0;
	}
	internal var m_auto_fade:int=0;
	public function p_EntityDistanceSquared(t_ent2:c_TEntity):Number{
		var t_xd:Number=t_ent2.m_mat.m_grid[3][0]-m_mat.m_grid[3][0];
		var t_yd:Number=t_ent2.m_mat.m_grid[3][1]-m_mat.m_grid[3][1];
		var t_zd:Number=-t_ent2.m_mat.m_grid[3][2]+m_mat.m_grid[3][2];
		return t_xd*t_xd+t_yd*t_yd+t_zd*t_zd;
	}
	public function p_EntityDistance(t_ent2:c_TEntity):Number{
		return Math.sqrt(this.p_EntityDistanceSquared(t_ent2));
	}
	internal var m_fade_near:Number=.0;
	internal var m_fade_far:Number=.0;
	internal var m_fade_alpha:Number=.0;
	internal var m_using_alpha:Boolean=false;
	internal var m_alpha_order:Number=.0;
	public function p_X():Number{
		return m_mat.m_grid[3][0];
	}
	public function p_X2(t_xx:Number):void{
		m_mat.m_grid[3][0]=t_xx;
	}
	public function p_Y():Number{
		return m_mat.m_grid[3][1];
	}
	public function p_Y2(t_yy:Number):void{
		m_mat.m_grid[3][1]=t_yy;
	}
	public function p_Z():Number{
		return -m_mat.m_grid[3][2];
	}
	public function p_Z2(t_zz:Number):void{
		m_mat.m_grid[3][2]=-t_zz;
	}
	internal static var m_temp_mat:c_Matrix;
	public function p_UpdateMatTrans(t_load_identity:Boolean):int{
		if(t_load_identity==false && ((m_parent)!=null)){
			m_mat.m_grid[3][0]=m_parent.m_mat.m_grid[0][0]*m_px+m_parent.m_mat.m_grid[1][0]*m_py+m_parent.m_mat.m_grid[2][0]*m_pz+m_parent.m_mat.m_grid[3][0];
			m_mat.m_grid[3][1]=m_parent.m_mat.m_grid[0][1]*m_px+m_parent.m_mat.m_grid[1][1]*m_py+m_parent.m_mat.m_grid[2][1]*m_pz+m_parent.m_mat.m_grid[3][1];
			m_mat.m_grid[3][2]=m_parent.m_mat.m_grid[0][2]*m_px+m_parent.m_mat.m_grid[1][2]*m_py+m_parent.m_mat.m_grid[2][2]*m_pz+m_parent.m_mat.m_grid[3][2];
		}else{
			m_mat.m_grid[3][0]=m_px;
			m_mat.m_grid[3][1]=m_py;
			m_mat.m_grid[3][2]=m_pz;
		}
		if(t_load_identity){
			m_loc_mat.p_Overwrite(m_mat);
		}
		return 0;
	}
	public static function m_UpdateChildren(t_ent_p:c_TEntity,t_type:int):int{
		var t_:c_Enumerator7=t_ent_p.m_child_list.p_ObjectEnumerator();
		while(t_.p_HasNext()){
			var t_ent_c:c_TEntity=t_.p_NextObject();
			if(((t_ent_c) as c_TBone)==null){
				if(t_type==0){
					t_ent_c.m_mat.p_Overwrite(t_ent_p.m_mat);
					t_ent_c.p_UpdateMat(false);
				}else{
					if(t_type==1){
						t_ent_c.p_UpdateMatTrans(false);
					}else{
						t_ent_c.m_mat.p_Overwrite(t_ent_p.m_mat);
						t_ent_c.p_UpdateMat(false);
					}
				}
				m_UpdateChildren(t_ent_c,t_type);
			}else{
				((t_ent_c) as c_TBone).p_UpdateMatrix(t_ent_c.m_loc_mat);
			}
		}
		return 0;
	}
	public function p_PositionEntity(t_x:Number,t_y:Number,t_z:Number,t_glob:int):c_TEntity{
		t_z=-t_z;
		if(t_glob==1 && m_parent!=null){
			m_temp_mat=m_parent.m_mat.p_Copy().p_Inverse();
			var t_psx:Number=m_parent.m_gsx;
			var t_psy:Number=m_parent.m_gsy;
			var t_psz:Number=m_parent.m_gsz;
			var t_pos:Array=m_temp_mat.p_TransformPoint(t_x,t_y,t_z,1.0);
			t_x=t_pos[0]/(t_psx*t_psx);
			t_y=t_pos[1]/(t_psy*t_psy);
			t_z=t_pos[2]/(t_psz*t_psz);
		}
		if(((this) as c_TBone)!=null){
			((this) as c_TBone).p_PositionBone(t_x,t_y,t_z,t_glob);
			return this;
		}
		m_px=t_x;
		m_py=t_y;
		m_pz=t_z;
		if(m_parent!=null){
			this.p_UpdateMatTrans(false);
		}else{
			this.p_UpdateMatTrans(true);
		}
		if(m_child_list.p_IsEmpty()!=true){
			m_UpdateChildren(this,1);
		}
		return this;
	}
	public function p_PositionEntity2(t_e:c_TEntity):c_TEntity{
		this.p_PositionEntity(t_e.p_X(),t_e.p_Y(),t_e.p_Z(),1);
		return this;
	}
	public function p_EntityPitch(t_glob:int):Number{
		if(t_glob==0){
			return -m_rx;
		}else{
			var t_ang:Number=(Math.atan2(m_mat.m_grid[2][1],Math.sqrt(m_mat.m_grid[2][0]*m_mat.m_grid[2][0]+m_mat.m_grid[2][2]*m_mat.m_grid[2][2]))*R2D);
			if(t_ang<=0.0001 && t_ang>=-0.0001){
				t_ang=0.0;
			}
			return t_ang;
		}
		return 0;
	}
	public function p_EntityYaw(t_glob:int):Number{
		if(t_glob==0){
			return m_ry;
		}else{
			var t_a:Number=m_mat.m_grid[2][0];
			var t_b:Number=m_mat.m_grid[2][2];
			if(t_a<=0.0001 && t_a>=-0.0001){
				t_a=0.0;
			}
			if(t_b<=0.0001 && t_b>=-0.0001){
				t_b=0.0;
			}
			return (Math.atan2(t_a,t_b)*R2D);
		}
		return 0;
	}
	public function p_EntityRoll(t_glob:int):Number{
		if(t_glob==0){
			return m_rz;
		}else{
			var t_a:Number=m_mat.m_grid[0][1];
			var t_b:Number=m_mat.m_grid[1][1];
			if(t_a<=0.0001 && t_a>=-0.0001){
				t_a=0.0;
			}
			if(t_b<=0.0001 && t_b>=-0.0001){
				t_b=0.0;
			}
			return (Math.atan2(t_a,t_b)*R2D);
		}
		return 0;
	}
	public function p_UpdateMatRot(t_load_identity:Boolean):int{
		if(t_load_identity==false && ((m_parent)!=null)){
			m_mat.m_grid[0][0]=m_parent.m_mat.m_grid[0][0];
			m_mat.m_grid[0][1]=m_parent.m_mat.m_grid[0][1];
			m_mat.m_grid[0][2]=m_parent.m_mat.m_grid[0][2];
			m_mat.m_grid[1][0]=m_parent.m_mat.m_grid[1][0];
			m_mat.m_grid[1][1]=m_parent.m_mat.m_grid[1][1];
			m_mat.m_grid[1][2]=m_parent.m_mat.m_grid[1][2];
			m_mat.m_grid[2][0]=m_parent.m_mat.m_grid[2][0];
			m_mat.m_grid[2][1]=m_parent.m_mat.m_grid[2][1];
			m_mat.m_grid[2][2]=m_parent.m_mat.m_grid[2][2];
			m_mat.p_Rotate(m_rx,m_ry,m_rz);
			m_mat.p_Scale(m_sx,m_sy,m_sz);
		}else{
			m_mat.p_FastRotateScale(m_rx,m_ry,m_rz,m_sx,m_sy,m_sz);
		}
		if((m_parent)!=null){
			m_gsx=m_parent.m_gsx*m_sx;
			m_gsy=m_parent.m_gsy*m_sy;
			m_gsz=m_parent.m_gsz*m_sz;
		}else{
			m_gsx=m_sx;
			m_gsy=m_sy;
			m_gsz=m_sz;
		}
		if(t_load_identity){
			m_loc_mat.p_Overwrite(m_mat);
		}
		return 0;
	}
	public function p_RotateEntity(t_x:Number,t_y:Number,t_z:Number,t_glob:int):c_TEntity{
		m_rx=-t_x;
		m_ry=t_y;
		m_rz=t_z;
		if(t_glob==1 && m_parent!=null){
			m_rx=m_rx+m_parent.p_EntityPitch(1);
			m_ry=m_ry-m_parent.p_EntityYaw(1);
			m_rz=m_rz-m_parent.p_EntityRoll(1);
		}
		if(((this) as c_TBone)!=null){
			((this) as c_TBone).p_RotateBone(m_rx,m_ry,m_rz,t_glob);
			return this;
		}
		if(m_parent!=null){
			this.p_UpdateMatRot(false);
		}else{
			this.p_UpdateMatRot(true);
		}
		if(m_child_list.p_IsEmpty()!=true){
			m_UpdateChildren(this,0);
		}
		return this;
	}
	public function p_RotateEntity2(t_e:c_TEntity):c_TEntity{
		this.p_RotateEntity(t_e.m_rx,t_e.m_ry,t_e.m_rz,1);
		return this;
	}
	public function p_EntityShininess(t_s:Number):c_TEntity{
		m_brush.m_shine=t_s;
		return this;
	}
	public function p_EntityTexture(t_texture:c_TTexture,t_frame:int,t_index:int):c_TEntity{
		m_brush.m_tex[t_index]=t_texture;
		if(t_index+1>m_brush.m_no_texs){
			m_brush.m_no_texs=t_index+1;
		}
		if(t_frame<0){
			t_frame=0;
		}
		if(t_frame>t_texture.m_no_frames-1){
			t_frame=t_texture.m_no_frames-1;
		}
		m_brush.m_tex[t_index].m_tex_frame=t_frame;
		if(t_frame>0 && t_texture.m_no_frames>1){
			var t_x:int=t_frame % t_texture.m_frame_xstep;
			var t_y:int=((t_frame/t_texture.m_frame_ystep)|0) % t_texture.m_frame_ystep;
			m_brush.m_tex[t_index].m_u_pos=(t_x)*t_texture.m_frame_ustep;
			m_brush.m_tex[t_index].m_v_pos=(t_y)*t_texture.m_frame_vstep;
		}
		return this;
	}
	public function p_HideEntity():c_TEntity{
		m_hide=true;
		var t_:c_Enumerator7=m_child_list.p_ObjectEnumerator();
		while(t_.p_HasNext()){
			var t_ent:c_TEntity=t_.p_NextObject();
			t_ent.p_HideEntity();
		}
		return this;
	}
	internal var m_anim:int=0;
	public function p_MoveEntity(t_mx:Number,t_my:Number,t_mz:Number):c_TEntity{
		t_mz=-t_mz;
		var t_n:Array=[];
		t_n=m_mat.p_TransformPoint(t_mx/m_gsx,t_my/m_gsy,t_mz/m_gsz,1.0);
		this.p_PositionEntity(t_n[0],t_n[1],-t_n[2],1);
		return this;
	}
	public function p_TurnEntity(t_x:Number,t_y:Number,t_z:Number,t_glob:int):c_TEntity{
		if(t_glob==1 && m_parent!=null){
		}
		m_rx=m_rx+-t_x;
		m_ry=m_ry+t_y;
		m_rz=m_rz+t_z;
		if(((this) as c_TBone)!=null){
			((this) as c_TBone).p_RotateBone(m_rx,m_ry,m_rz,t_glob);
			return this;
		}
		if(m_parent!=null){
			this.p_UpdateMatRot(false);
		}else{
			this.p_UpdateMatRot(true);
		}
		if(m_child_list.p_IsEmpty()!=true){
			m_UpdateChildren(this,0);
		}
		return this;
	}
	public function p_EntityScaleX(t_glob:int):Number{
		if(t_glob==1){
			if(m_parent!=null){
				var t_ent:c_TEntity=this;
				var t_x:Number=m_sx;
				do{
					t_x=t_x*t_ent.m_parent.m_sx;
					t_ent=t_ent.m_parent;
				}while(!(t_ent.m_parent==null));
				return t_x;
			}
		}
		return m_sx;
	}
	public function p_EntityScaleY(t_glob:int):Number{
		if(t_glob==1){
			if(m_parent!=null){
				var t_ent:c_TEntity=this;
				var t_y:Number=m_sy;
				do{
					t_y=t_y*t_ent.m_parent.m_sy;
					t_ent=t_ent.m_parent;
				}while(!(t_ent.m_parent==null));
				return t_y;
			}
		}
		return m_sy;
	}
	public function p_EntityScaleZ(t_glob:int):Number{
		if(t_glob==1){
			if(m_parent!=null){
				var t_ent:c_TEntity=this;
				var t_z:Number=m_sz;
				do{
					t_z=t_z*t_ent.m_parent.m_sz;
					t_ent=t_ent.m_parent;
				}while(!(t_ent.m_parent==null));
				return t_z;
			}
		}
		return m_sz;
	}
	public function p_ScaleEntity(t_x:Number,t_y:Number,t_z:Number,t_glob:int):c_TEntity{
		m_sx=t_x;
		m_sy=t_y;
		m_sz=t_z;
		if(t_glob==1 && m_parent!=null){
			m_sx=m_sx/m_parent.m_gsx;
			m_sy=m_sy/m_parent.m_gsy;
			m_sz=m_sz/m_parent.m_gsz;
		}
		if(((this) as c_TBone)!=null){
			((this) as c_TBone).p_ScaleBone(m_sx,m_sy,m_sz,t_glob);
			return null;
		}
		if(m_parent!=null){
			this.p_UpdateMatRot(false);
		}else{
			this.p_UpdateMatRot(true);
		}
		if(m_child_list.p_IsEmpty()!=true){
			m_UpdateChildren(this,0);
		}
		return this;
	}
	public function p_ScaleEntity2(t_e:c_TEntity):c_TEntity{
		this.p_ScaleEntity(t_e.p_EntityScaleX(0),t_e.p_EntityScaleY(0),t_e.p_EntityScaleZ(0),1);
		return this;
	}
	public function p_EntityParent(t_parent_ent:c_TEntity,t_glob:Boolean):c_TEntity{
		var t_gpx_:Number=this.p_EntityX(1);
		var t_gpy_:Number=this.p_EntityY(1);
		var t_gpz_:Number=this.p_EntityZ(1);
		var t_grx_:Number=this.p_EntityPitch(1);
		var t_gry_:Number=this.p_EntityYaw(1);
		var t_grz_:Number=this.p_EntityRoll(1);
		if(m_parent!=null){
			m_parent_link.p_Remove();
			m_parent=null;
		}
		m_px=t_gpx_;
		m_py=t_gpy_;
		m_pz=-t_gpz_;
		m_rx=-t_grx_;
		m_ry=t_gry_;
		m_rz=t_grz_;
		if(t_parent_ent==null){
			this.p_UpdateMat(true);
			return null;
		}
		if(t_parent_ent!=null){
			if(t_glob){
				this.p_AddParent(t_parent_ent);
				this.p_PositionEntity(t_gpx_,t_gpy_,t_gpz_,1);
				this.p_RotateEntity(t_grx_,t_gry_,t_grz_,1);
				this.p_ScaleEntity(m_gsx,m_gsy,m_gsz,1);
			}else{
				this.p_AddParent(t_parent_ent);
			}
		}
		return this;
	}
	public function p_EntityName():String{
		return m_name;
	}
	internal static var m_global_mat:c_Matrix;
	public function p_EntityBlend(t_blend_no:int):c_TEntity{
		m_brush.m_blend=t_blend_no;
		if(((this) as c_TMesh)!=null){
			var t_:c_Enumerator8=((this) as c_TMesh).m_surf_list.p_ObjectEnumerator();
			while(t_.p_HasNext()){
				var t_surf:c_TSurface=t_.p_NextObject();
				if(t_surf.m_brush!=null){
					t_surf.m_brush.m_blend=m_brush.m_blend;
				}
			}
		}
		return this;
	}
	public function p_EntityColorFloat(t_r:Number,t_g:Number,t_b:Number,t_a:Number):c_TEntity{
		m_brush.m_red=t_r;
		m_brush.m_green=t_g;
		m_brush.m_blue=t_b;
		if(t_a>=0.0){
			m_brush.m_alpha=t_a;
		}
		return this;
	}
}
class c_TMesh extends c_TEntity{
	public function m_TMesh_new():c_TMesh{
		super.m_TEntity_new();
		return this;
	}
	public static function m_CreateMesh(t_parent_ent:c_TEntity):c_TMesh{
		var t_mesh:c_TMesh=(new c_TMesh).m_TMesh_new();
		t_mesh.m_classname="Mesh";
		if((t_parent_ent)!=null){
			t_mesh.p_AddParent(t_parent_ent);
		}
		t_mesh.m_entity_link=c_TEntity.m_entity_list.p_EntityListAdd(t_mesh);
		if(t_mesh.m_parent!=null){
			t_mesh.m_mat.p_Overwrite(t_mesh.m_parent.m_mat);
			t_mesh.p_UpdateMat(false);
		}else{
			t_mesh.p_UpdateMat(true);
		}
		return t_mesh;
	}
	internal var m_surf_list:c_List2=(new c_List2).m_List_new();
	internal var m_no_surfs:int=0;
	public function p_CreateSurfaceID():int{
		m_no_surfs=m_no_surfs+1;
		return m_no_surfs-1;
	}
	internal var m_anim_surf:Array=[];
	internal var m_anim_surf_frame:Array=[];
	internal var m_reset_bounds:int=1;
	internal var m_col_tree:c_TColTree=(new c_TColTree).m_TColTree_new();
	public function p_CreateSurface(t_bru:c_TBrush):c_TSurface{
		var t_surf:c_TSurface=(new c_TSurface).m_TSurface_new();
		m_surf_list.p_AddLast2(t_surf);
		if(t_bru!=null){
			t_surf.m_brush=t_bru.p_Copy();
		}
		t_surf.m_surf_id=this.p_CreateSurfaceID();
		m_anim_surf=resize_object_array(m_anim_surf,m_no_surfs);
		m_anim_surf_frame=resize_number_array(m_anim_surf_frame,m_no_surfs);
		m_reset_bounds=1;
		m_col_tree.m_reset_col_tree=1;
		return t_surf;
	}
	public function p_AddSurface(t_surf:c_TSurface):c_TSurface{
		m_surf_list.p_AddLast2(t_surf);
		t_surf.m_surf_id=this.p_CreateSurfaceID();
		m_anim_surf=resize_object_array(m_anim_surf,m_no_surfs);
		m_anim_surf_frame=resize_number_array(m_anim_surf_frame,m_no_surfs);
		m_reset_bounds=1;
		m_col_tree.m_reset_col_tree=1;
		return t_surf;
	}
	public function p_GetTotalTris():int{
		var t_t:int=0;
		var t_:c_Enumerator8=m_surf_list.p_ObjectEnumerator();
		while(t_.p_HasNext()){
			var t_s:c_TSurface=t_.p_NextObject();
			t_t=t_t+t_s.m_no_tris;
		}
		return t_t;
	}
	internal var m_total_tris:int=0;
	internal var m_min_x:Number=.0;
	internal var m_max_x:Number=.0;
	internal var m_min_y:Number=.0;
	internal var m_max_y:Number=.0;
	internal var m_min_z:Number=.0;
	internal var m_max_z:Number=.0;
	internal var m_vec_temp:c_Vector=(new c_Vector).m_Vector_new(0.0,0.0,0.0);
	internal var m_vecbounds:Array=new_object_array(6);
	internal var m_center_x:Number=.0;
	internal var m_center_y:Number=.0;
	internal var m_center_z:Number=.0;
	public function p_GetBounds(t_reset:Boolean):int{
		if(m_reset_bounds==1 || t_reset==true){
			m_total_tris=this.p_GetTotalTris();
			m_reset_bounds=0;
			m_min_x=999999999.0;
			m_max_x=-999999999.0;
			m_min_y=999999999.0;
			m_max_y=-999999999.0;
			m_min_z=999999999.0;
			m_max_z=-999999999.0;
			var t_cc:int=0;
			var t_:c_Enumerator8=m_surf_list.p_ObjectEnumerator();
			while(t_.p_HasNext()){
				var t_surf:c_TSurface=t_.p_NextObject();
				t_cc+=1;
				for(var t_v:int=0;t_v<t_surf.m_no_verts;t_v=t_v+1){
					t_surf.m_vert_data.p_GetVertCoords(m_vec_temp,t_v);
					if(m_vec_temp.m_x<m_min_x){
						m_min_x=m_vec_temp.m_x;
						m_vecbounds[0]=m_vec_temp.p_Copy();
					}
					if(m_vec_temp.m_x>m_max_x){
						m_max_x=m_vec_temp.m_x;
						m_vecbounds[1]=m_vec_temp.p_Copy();
					}
					if(m_vec_temp.m_y<m_min_y){
						m_min_y=m_vec_temp.m_y;
						m_vecbounds[2]=m_vec_temp.p_Copy();
					}
					if(m_vec_temp.m_y>m_max_y){
						m_max_y=m_vec_temp.m_y;
						m_vecbounds[3]=m_vec_temp.p_Copy();
					}
					if(m_vec_temp.m_z<m_min_z){
						m_min_z=m_vec_temp.m_z;
						m_vecbounds[4]=m_vec_temp.p_Copy();
					}
					if(m_vec_temp.m_z>m_max_z){
						m_max_z=m_vec_temp.m_z;
						m_vecbounds[5]=m_vec_temp.p_Copy();
					}
				}
			}
			var t_width:Number=m_max_x-m_min_x;
			var t_height:Number=m_max_y-m_min_y;
			var t_depth:Number=m_max_z-m_min_z;
			if(t_cc==0){
				t_width=0.0;
				t_height=0.0;
				t_depth=0.0;
			}
			if(m_cull_radius>=0.0){
				if(t_width>=t_height && t_width>=t_depth){
					m_cull_radius=t_width;
				}else{
					if(t_height>=t_width && t_height>=t_depth){
						m_cull_radius=t_height;
					}else{
						m_cull_radius=t_depth;
					}
				}
				m_cull_radius=m_cull_radius*0.5;
				var t_crs:Number=m_cull_radius*m_cull_radius;
				m_cull_radius=Math.sqrt(t_crs+t_crs+t_crs);
			}
			m_center_x=m_min_x+t_width*0.5;
			m_center_y=m_min_y+t_height*0.5;
			m_center_z=m_min_z+t_depth*0.5;
		}
		return 0;
	}
	internal var m_distance_nearplane:Number=.0;
	internal var m_culled:Boolean=false;
	internal var m_wireframe:Boolean=false;
	public function p_AutoFade(t_cam:c_TCamera):int{
		var t_dist:Number=t_cam.p_EntityDistance(this);
		if(t_dist>m_fade_near && t_dist<m_fade_far){
			m_fade_alpha=(t_dist-m_fade_near)/(m_fade_far-m_fade_near);
		}else{
			if(t_dist<m_fade_near){
				m_fade_alpha=0.0;
			}else{
				m_fade_alpha=1.0;
			}
		}
		return 0;
	}
	public function p_Alpha():Boolean{
		var t_alpha:Boolean=false;
		if(m_brush.m_alpha<1.0 || m_brush.m_blend==2 || m_brush.m_blend==3 || ((m_brush.m_fx&32)!=0)){
			t_alpha=true;
		}else{
			if(m_brush.m_tex[0]!=null){
				if((m_brush.m_tex[0].m_flags&2)!=0){
					t_alpha=true;
				}
			}
		}
		var t_:c_Enumerator8=m_surf_list.p_ObjectEnumerator();
		while(t_.p_HasNext()){
			var t_surf:c_TSurface=t_.p_NextObject();
			t_surf.m_alpha_enable=false;
			if(t_surf.m_brush!=null){
				if(t_surf.m_brush.m_alpha<1.0 || t_surf.m_brush.m_blend==2 || t_surf.m_brush.m_blend==3 || ((t_surf.m_brush.m_fx&32)!=0)){
					t_alpha=true;
				}else{
					if(t_surf.m_brush.m_tex[0]!=null){
						if((t_surf.m_brush.m_tex[0].m_flags&2)!=0){
							t_alpha=true;
						}
					}
				}
			}
			if(m_fade_alpha!=0.0){
				t_alpha=true;
			}
			if(t_alpha==true){
				t_surf.m_alpha_enable=true;
			}
		}
		m_using_alpha=t_alpha;
		return t_alpha;
	}
	internal var m_is_sprite:Boolean=false;
	public static function m_CreateCube(t_parent_ent:c_TEntity):c_TMesh{
		var t_mesh:c_TMesh=m_CreateMesh(t_parent_ent);
		var t_surf:c_TSurface=t_mesh.p_CreateSurface(null);
		t_surf.p_AddVertex(-1.0,-1.0,-1.0,0.0,0.0,0.0);
		t_surf.p_AddVertex(-1.0,1.0,-1.0,0.0,0.0,0.0);
		t_surf.p_AddVertex(1.0,1.0,-1.0,0.0,0.0,0.0);
		t_surf.p_AddVertex(1.0,-1.0,-1.0,0.0,0.0,0.0);
		t_surf.p_AddVertex(-1.0,-1.0,1.0,0.0,0.0,0.0);
		t_surf.p_AddVertex(-1.0,1.0,1.0,0.0,0.0,0.0);
		t_surf.p_AddVertex(1.0,1.0,1.0,0.0,0.0,0.0);
		t_surf.p_AddVertex(1.0,-1.0,1.0,0.0,0.0,0.0);
		t_surf.p_AddVertex(-1.0,-1.0,1.0,0.0,0.0,0.0);
		t_surf.p_AddVertex(-1.0,1.0,1.0,0.0,0.0,0.0);
		t_surf.p_AddVertex(1.0,1.0,1.0,0.0,0.0,0.0);
		t_surf.p_AddVertex(1.0,-1.0,1.0,0.0,0.0,0.0);
		t_surf.p_AddVertex(-1.0,-1.0,-1.0,0.0,0.0,0.0);
		t_surf.p_AddVertex(-1.0,1.0,-1.0,0.0,0.0,0.0);
		t_surf.p_AddVertex(1.0,1.0,-1.0,0.0,0.0,0.0);
		t_surf.p_AddVertex(1.0,-1.0,-1.0,0.0,0.0,0.0);
		t_surf.p_AddVertex(-1.0,-1.0,1.0,0.0,0.0,0.0);
		t_surf.p_AddVertex(-1.0,1.0,1.0,0.0,0.0,0.0);
		t_surf.p_AddVertex(1.0,1.0,1.0,0.0,0.0,0.0);
		t_surf.p_AddVertex(1.0,-1.0,1.0,0.0,0.0,0.0);
		t_surf.p_AddVertex(-1.0,-1.0,-1.0,0.0,0.0,0.0);
		t_surf.p_AddVertex(-1.0,1.0,-1.0,0.0,0.0,0.0);
		t_surf.p_AddVertex(1.0,1.0,-1.0,0.0,0.0,0.0);
		t_surf.p_AddVertex(1.0,-1.0,-1.0,0.0,0.0,0.0);
		t_surf.p_VertexNormal(0,0.0,0.0,-1.0);
		t_surf.p_VertexNormal(1,0.0,0.0,-1.0);
		t_surf.p_VertexNormal(2,0.0,0.0,-1.0);
		t_surf.p_VertexNormal(3,0.0,0.0,-1.0);
		t_surf.p_VertexNormal(4,0.0,0.0,1.0);
		t_surf.p_VertexNormal(5,0.0,0.0,1.0);
		t_surf.p_VertexNormal(6,0.0,0.0,1.0);
		t_surf.p_VertexNormal(7,0.0,0.0,1.0);
		t_surf.p_VertexNormal(8,0.0,-1.0,0.0);
		t_surf.p_VertexNormal(9,0.0,1.0,0.0);
		t_surf.p_VertexNormal(10,0.0,1.0,0.0);
		t_surf.p_VertexNormal(11,0.0,-1.0,0.0);
		t_surf.p_VertexNormal(12,0.0,-1.0,0.0);
		t_surf.p_VertexNormal(13,0.0,1.0,0.0);
		t_surf.p_VertexNormal(14,0.0,1.0,0.0);
		t_surf.p_VertexNormal(15,0.0,-1.0,0.0);
		t_surf.p_VertexNormal(16,-1.0,0.0,0.0);
		t_surf.p_VertexNormal(17,-1.0,0.0,0.0);
		t_surf.p_VertexNormal(18,1.0,0.0,0.0);
		t_surf.p_VertexNormal(19,1.0,0.0,0.0);
		t_surf.p_VertexNormal(20,-1.0,0.0,0.0);
		t_surf.p_VertexNormal(21,-1.0,0.0,0.0);
		t_surf.p_VertexNormal(22,1.0,0.0,0.0);
		t_surf.p_VertexNormal(23,1.0,0.0,0.0);
		t_surf.p_VertexTexCoords(0,0.0,1.0,0.0,0);
		t_surf.p_VertexTexCoords(1,0.0,0.0,0.0,0);
		t_surf.p_VertexTexCoords(2,1.0,0.0,0.0,0);
		t_surf.p_VertexTexCoords(3,1.0,1.0,0.0,0);
		t_surf.p_VertexTexCoords(4,1.0,1.0,0.0,0);
		t_surf.p_VertexTexCoords(5,1.0,0.0,0.0,0);
		t_surf.p_VertexTexCoords(6,0.0,0.0,0.0,0);
		t_surf.p_VertexTexCoords(7,0.0,1.0,0.0,0);
		t_surf.p_VertexTexCoords(8,0.0,1.0,0.0,0);
		t_surf.p_VertexTexCoords(9,0.0,0.0,0.0,0);
		t_surf.p_VertexTexCoords(10,1.0,0.0,0.0,0);
		t_surf.p_VertexTexCoords(11,1.0,1.0,0.0,0);
		t_surf.p_VertexTexCoords(12,0.0,0.0,0.0,0);
		t_surf.p_VertexTexCoords(13,0.0,1.0,0.0,0);
		t_surf.p_VertexTexCoords(14,1.0,1.0,0.0,0);
		t_surf.p_VertexTexCoords(15,1.0,0.0,0.0,0);
		t_surf.p_VertexTexCoords(16,0.0,1.0,0.0,0);
		t_surf.p_VertexTexCoords(17,0.0,0.0,0.0,0);
		t_surf.p_VertexTexCoords(18,1.0,0.0,0.0,0);
		t_surf.p_VertexTexCoords(19,1.0,1.0,0.0,0);
		t_surf.p_VertexTexCoords(20,1.0,1.0,0.0,0);
		t_surf.p_VertexTexCoords(21,1.0,0.0,0.0,0);
		t_surf.p_VertexTexCoords(22,0.0,0.0,0.0,0);
		t_surf.p_VertexTexCoords(23,0.0,1.0,0.0,0);
		t_surf.p_VertexTexCoords(0,0.0,1.0,0.0,1);
		t_surf.p_VertexTexCoords(1,0.0,0.0,0.0,1);
		t_surf.p_VertexTexCoords(2,1.0,0.0,0.0,1);
		t_surf.p_VertexTexCoords(3,1.0,1.0,0.0,1);
		t_surf.p_VertexTexCoords(4,1.0,1.0,0.0,1);
		t_surf.p_VertexTexCoords(5,1.0,0.0,0.0,1);
		t_surf.p_VertexTexCoords(6,0.0,0.0,0.0,1);
		t_surf.p_VertexTexCoords(7,0.0,1.0,0.0,1);
		t_surf.p_VertexTexCoords(8,0.0,1.0,0.0,1);
		t_surf.p_VertexTexCoords(9,0.0,0.0,0.0,1);
		t_surf.p_VertexTexCoords(10,1.0,0.0,0.0,1);
		t_surf.p_VertexTexCoords(11,1.0,1.0,0.0,1);
		t_surf.p_VertexTexCoords(12,0.0,0.0,0.0,1);
		t_surf.p_VertexTexCoords(13,0.0,1.0,0.0,1);
		t_surf.p_VertexTexCoords(14,1.0,1.0,0.0,1);
		t_surf.p_VertexTexCoords(15,1.0,0.0,0.0,1);
		t_surf.p_VertexTexCoords(16,0.0,1.0,0.0,1);
		t_surf.p_VertexTexCoords(17,0.0,0.0,0.0,1);
		t_surf.p_VertexTexCoords(18,1.0,0.0,0.0,1);
		t_surf.p_VertexTexCoords(19,1.0,1.0,0.0,1);
		t_surf.p_VertexTexCoords(20,1.0,1.0,0.0,1);
		t_surf.p_VertexTexCoords(21,1.0,0.0,0.0,1);
		t_surf.p_VertexTexCoords(22,0.0,0.0,0.0,1);
		t_surf.p_VertexTexCoords(23,0.0,1.0,0.0,1);
		t_surf.p_AddTriangle(0,1,2);
		t_surf.p_AddTriangle(0,2,3);
		t_surf.p_AddTriangle(6,5,4);
		t_surf.p_AddTriangle(7,6,4);
		t_surf.p_AddTriangle(14,13,9);
		t_surf.p_AddTriangle(10,14,9);
		t_surf.p_AddTriangle(8,12,15);
		t_surf.p_AddTriangle(8,15,11);
		t_surf.p_AddTriangle(22,18,19);
		t_surf.p_AddTriangle(23,22,19);
		t_surf.p_AddTriangle(16,17,21);
		t_surf.p_AddTriangle(16,21,20);
		t_surf.p_CropSurfaceBuffers();
		t_mesh.m_classname="MeshCube";
		return t_mesh;
	}
	public function p_Draw(t_x:Number,t_y:Number,t_no_scaling:Boolean):int{
		c_TRender.m_draw_list.p_AddLast3(this);
		var t_w:Number=.0;
		var t_h:Number=.0;
		if(m_parent!=null){
			this.p_EntityParent(null,true);
		}
		this.p_PositionEntity(t_x,t_y,1.99999,0);
		var t_spr:c_TSprite=((this) as c_TSprite);
		if(!t_no_scaling && t_spr!=null){
			t_spr.m_pixel_scale[0]=1.0;
			t_spr.m_pixel_scale[1]=1.0;
			if(((this) as c_TText)!=null){
				var t_scx:Number=((((this) as c_TText).m_char_pixels*((this) as c_TText).m_pixel_ratio+1.5)|0);
				t_spr.m_pixel_scale[0]=t_scx;
				t_spr.m_pixel_scale[1]=t_scx;
			}else{
				var t_scx2:Number=(this.m_brush.p_GetTexture(0).m_width)*0.5;
				var t_scy:Number=(this.m_brush.p_GetTexture(0).m_height)*0.5;
				t_spr.m_pixel_scale[0]=t_scx2;
				t_spr.m_pixel_scale[1]=t_scy;
			}
		}
		return 0;
	}
	public function p_GetAnimSurface(t_surf:c_TSurface):c_TSurface{
		return m_anim_surf[t_surf.m_surf_id];
	}
	public function p_GetAnimSurface2(t_s:int):c_TSurface{
		if(t_s<0 || t_s>m_anim_surf.length){
			return null;
		}
		return m_anim_surf[t_s-1];
	}
	public function p_UpdateVertexAnimFrame(t_surf:c_TSurface,t_orig_surf:c_TSurface):void{
		if(!((t_surf)!=null)){
			return;
		}
		t_surf.m_anim_frame=this.m_anim_surf_frame[t_orig_surf.m_surf_id];
		t_surf.m_reset_vbo=t_surf.m_reset_vbo|1;
	}
	public function p_GetSurface(t_surf_no_get:int):c_TSurface{
		var t_surf_no:int=0;
		var t_:c_Enumerator8=m_surf_list.p_ObjectEnumerator();
		while(t_.p_HasNext()){
			var t_surf:c_TSurface=t_.p_NextObject();
			t_surf_no=t_surf_no+1;
			if(t_surf_no_get==t_surf_no){
				return t_surf;
			}
		}
		return null;
	}
	public function p_RemoveFromRenderList():void{
		m_entity_link.p_Remove();
		m_entity_link=null;
	}
}
class c_Matrix extends Object{
	internal var m_grid:Array=new_array_array(4);
	public function m_Matrix_new():c_Matrix{
		m_grid=[[0.0,0.0,0.0,0.0],[0.0,0.0,0.0,0.0],[0.0,0.0,0.0,0.0],[0.0,0.0,0.0,0.0]];
		return this;
	}
	public function m_Matrix_new2(t_a:c_Vector,t_b:c_Vector,t_c:c_Vector):c_Matrix{
		m_grid[0]=[t_a.m_x,t_a.m_y,t_a.m_z,0.0];
		m_grid[1]=[t_b.m_x,t_b.m_y,t_b.m_z,0.0];
		m_grid[2]=[t_c.m_x,t_c.m_y,t_c.m_z,0.0];
		m_grid[3]=[0.0,0.0,0.0,1.0];
		return this;
	}
	public function p_LoadIdentity():void{
		m_grid[0][0]=1.0;
		m_grid[0][1]=0.0;
		m_grid[0][2]=0.0;
		m_grid[0][3]=0.0;
		m_grid[1][0]=0.0;
		m_grid[1][1]=1.0;
		m_grid[1][2]=0.0;
		m_grid[1][3]=0.0;
		m_grid[2][0]=0.0;
		m_grid[2][1]=0.0;
		m_grid[2][2]=1.0;
		m_grid[2][3]=0.0;
		m_grid[3][0]=0.0;
		m_grid[3][1]=0.0;
		m_grid[3][2]=0.0;
		m_grid[3][3]=1.0;
	}
	public function p_Overwrite(t_mat:c_Matrix):void{
		m_grid[0][0]=t_mat.m_grid[0][0];
		m_grid[1][0]=t_mat.m_grid[1][0];
		m_grid[2][0]=t_mat.m_grid[2][0];
		m_grid[3][0]=t_mat.m_grid[3][0];
		m_grid[0][1]=t_mat.m_grid[0][1];
		m_grid[1][1]=t_mat.m_grid[1][1];
		m_grid[2][1]=t_mat.m_grid[2][1];
		m_grid[3][1]=t_mat.m_grid[3][1];
		m_grid[0][2]=t_mat.m_grid[0][2];
		m_grid[1][2]=t_mat.m_grid[1][2];
		m_grid[2][2]=t_mat.m_grid[2][2];
		m_grid[3][2]=t_mat.m_grid[3][2];
		m_grid[0][3]=t_mat.m_grid[0][3];
		m_grid[1][3]=t_mat.m_grid[1][3];
		m_grid[2][3]=t_mat.m_grid[2][3];
		m_grid[3][3]=t_mat.m_grid[3][3];
	}
	public function p_Translate(t_x:Number,t_y:Number,t_z:Number):void{
		m_grid[3][0]=m_grid[0][0]*t_x+m_grid[1][0]*t_y+m_grid[2][0]*t_z+m_grid[3][0];
		m_grid[3][1]=m_grid[0][1]*t_x+m_grid[1][1]*t_y+m_grid[2][1]*t_z+m_grid[3][1];
		m_grid[3][2]=m_grid[0][2]*t_x+m_grid[1][2]*t_y+m_grid[2][2]*t_z+m_grid[3][2];
	}
	public function p_Rotate(t_rx:Number,t_ry:Number,t_rz:Number):void{
		var t_cos_ang:Number=.0;
		var t_sin_ang:Number=.0;
		var t_m20:Number=.0;
		var t_m21:Number=.0;
		var t_m22:Number=.0;
		var t_m00:Number=.0;
		var t_m01:Number=.0;
		var t_m02:Number=.0;
		var t_r1:Number=.0;
		var t_r2:Number=.0;
		var t_r3:Number=.0;
		t_cos_ang=Math.cos((t_ry)*D2R);
		t_sin_ang=Math.sin((t_ry)*D2R);
		t_m00=m_grid[0][0]*t_cos_ang+m_grid[2][0]*-t_sin_ang;
		t_m01=m_grid[0][1]*t_cos_ang+m_grid[2][1]*-t_sin_ang;
		t_m02=m_grid[0][2]*t_cos_ang+m_grid[2][2]*-t_sin_ang;
		t_m20=m_grid[0][0]*t_sin_ang+m_grid[2][0]*t_cos_ang;
		t_m21=m_grid[0][1]*t_sin_ang+m_grid[2][1]*t_cos_ang;
		t_m22=m_grid[0][2]*t_sin_ang+m_grid[2][2]*t_cos_ang;
		t_cos_ang=Math.cos((t_rx)*D2R);
		t_sin_ang=Math.sin((t_rx)*D2R);
		var t_m10:Number=m_grid[1][0]*t_cos_ang+t_m20*t_sin_ang;
		var t_m11:Number=m_grid[1][1]*t_cos_ang+t_m21*t_sin_ang;
		var t_m12:Number=m_grid[1][2]*t_cos_ang+t_m22*t_sin_ang;
		m_grid[2][0]=m_grid[1][0]*-t_sin_ang+t_m20*t_cos_ang;
		m_grid[2][1]=m_grid[1][1]*-t_sin_ang+t_m21*t_cos_ang;
		m_grid[2][2]=m_grid[1][2]*-t_sin_ang+t_m22*t_cos_ang;
		t_cos_ang=Math.cos((t_rz)*D2R);
		t_sin_ang=Math.sin((t_rz)*D2R);
		m_grid[0][0]=t_m00*t_cos_ang+t_m10*t_sin_ang;
		m_grid[0][1]=t_m01*t_cos_ang+t_m11*t_sin_ang;
		m_grid[0][2]=t_m02*t_cos_ang+t_m12*t_sin_ang;
		m_grid[1][0]=t_m00*-t_sin_ang+t_m10*t_cos_ang;
		m_grid[1][1]=t_m01*-t_sin_ang+t_m11*t_cos_ang;
		m_grid[1][2]=t_m02*-t_sin_ang+t_m12*t_cos_ang;
	}
	public function p_Scale(t_sx:Number,t_sy:Number,t_sz:Number):void{
		if(t_sx==1.0 && t_sy==1.0 && t_sz==1.0){
			return;
		}
		m_grid[0][0]=m_grid[0][0]*t_sx;
		m_grid[0][1]=m_grid[0][1]*t_sx;
		m_grid[0][2]=m_grid[0][2]*t_sx;
		m_grid[1][0]=m_grid[1][0]*t_sy;
		m_grid[1][1]=m_grid[1][1]*t_sy;
		m_grid[1][2]=m_grid[1][2]*t_sy;
		m_grid[2][0]=m_grid[2][0]*t_sz;
		m_grid[2][1]=m_grid[2][1]*t_sz;
		m_grid[2][2]=m_grid[2][2]*t_sz;
	}
	public function p_Inverse():c_Matrix{
		var t_mat:c_Matrix=(new c_Matrix).m_Matrix_new();
		var t_tx:Number=0.0;
		var t_ty:Number=0.0;
		var t_tz:Number=0.0;
		t_mat.m_grid[0][0]=m_grid[0][0];
		t_mat.m_grid[1][0]=m_grid[0][1];
		t_mat.m_grid[2][0]=m_grid[0][2];
		t_mat.m_grid[0][1]=m_grid[1][0];
		t_mat.m_grid[1][1]=m_grid[1][1];
		t_mat.m_grid[2][1]=m_grid[1][2];
		t_mat.m_grid[0][2]=m_grid[2][0];
		t_mat.m_grid[1][2]=m_grid[2][1];
		t_mat.m_grid[2][2]=m_grid[2][2];
		t_mat.m_grid[0][3]=0.0;
		t_mat.m_grid[1][3]=0.0;
		t_mat.m_grid[2][3]=0.0;
		t_mat.m_grid[3][3]=1.0;
		t_tx=m_grid[3][0];
		t_ty=m_grid[3][1];
		t_tz=m_grid[3][2];
		t_mat.m_grid[3][0]=-(m_grid[0][0]*t_tx+m_grid[0][1]*t_ty+m_grid[0][2]*t_tz);
		t_mat.m_grid[3][1]=-(m_grid[1][0]*t_tx+m_grid[1][1]*t_ty+m_grid[1][2]*t_tz);
		t_mat.m_grid[3][2]=-(m_grid[2][0]*t_tx+m_grid[2][1]*t_ty+m_grid[2][2]*t_tz);
		return t_mat;
	}
	public function p_Multiply4(t_mat:c_Matrix):void{
		var t_m00:Number=m_grid[0][0]*t_mat.m_grid[0][0]+m_grid[1][0]*t_mat.m_grid[0][1]+m_grid[2][0]*t_mat.m_grid[0][2]+m_grid[3][0]*t_mat.m_grid[0][3];
		var t_m01:Number=m_grid[0][1]*t_mat.m_grid[0][0]+m_grid[1][1]*t_mat.m_grid[0][1]+m_grid[2][1]*t_mat.m_grid[0][2]+m_grid[3][1]*t_mat.m_grid[0][3];
		var t_m02:Number=m_grid[0][2]*t_mat.m_grid[0][0]+m_grid[1][2]*t_mat.m_grid[0][1]+m_grid[2][2]*t_mat.m_grid[0][2]+m_grid[3][2]*t_mat.m_grid[0][3];
		var t_m03:Number=m_grid[0][3]*t_mat.m_grid[0][0]+m_grid[1][3]*t_mat.m_grid[0][1]+m_grid[2][3]*t_mat.m_grid[0][2]+m_grid[3][3]*t_mat.m_grid[0][3];
		var t_m10:Number=m_grid[0][0]*t_mat.m_grid[1][0]+m_grid[1][0]*t_mat.m_grid[1][1]+m_grid[2][0]*t_mat.m_grid[1][2]+m_grid[3][0]*t_mat.m_grid[1][3];
		var t_m11:Number=m_grid[0][1]*t_mat.m_grid[1][0]+m_grid[1][1]*t_mat.m_grid[1][1]+m_grid[2][1]*t_mat.m_grid[1][2]+m_grid[3][1]*t_mat.m_grid[1][3];
		var t_m12:Number=m_grid[0][2]*t_mat.m_grid[1][0]+m_grid[1][2]*t_mat.m_grid[1][1]+m_grid[2][2]*t_mat.m_grid[1][2]+m_grid[3][2]*t_mat.m_grid[1][3];
		var t_m13:Number=m_grid[0][3]*t_mat.m_grid[1][0]+m_grid[1][3]*t_mat.m_grid[1][1]+m_grid[2][3]*t_mat.m_grid[1][2]+m_grid[3][3]*t_mat.m_grid[1][3];
		var t_m20:Number=m_grid[0][0]*t_mat.m_grid[2][0]+m_grid[1][0]*t_mat.m_grid[2][1]+m_grid[2][0]*t_mat.m_grid[2][2]+m_grid[3][0]*t_mat.m_grid[2][3];
		var t_m21:Number=m_grid[0][1]*t_mat.m_grid[2][0]+m_grid[1][1]*t_mat.m_grid[2][1]+m_grid[2][1]*t_mat.m_grid[2][2]+m_grid[3][1]*t_mat.m_grid[2][3];
		var t_m22:Number=m_grid[0][2]*t_mat.m_grid[2][0]+m_grid[1][2]*t_mat.m_grid[2][1]+m_grid[2][2]*t_mat.m_grid[2][2]+m_grid[3][2]*t_mat.m_grid[2][3];
		var t_m23:Number=m_grid[0][3]*t_mat.m_grid[2][0]+m_grid[1][3]*t_mat.m_grid[2][1]+m_grid[2][3]*t_mat.m_grid[2][2]+m_grid[3][3]*t_mat.m_grid[2][3];
		var t_m30:Number=m_grid[0][0]*t_mat.m_grid[3][0]+m_grid[1][0]*t_mat.m_grid[3][1]+m_grid[2][0]*t_mat.m_grid[3][2]+m_grid[3][0]*t_mat.m_grid[3][3];
		var t_m31:Number=m_grid[0][1]*t_mat.m_grid[3][0]+m_grid[1][1]*t_mat.m_grid[3][1]+m_grid[2][1]*t_mat.m_grid[3][2]+m_grid[3][1]*t_mat.m_grid[3][3];
		var t_m32:Number=m_grid[0][2]*t_mat.m_grid[3][0]+m_grid[1][2]*t_mat.m_grid[3][1]+m_grid[2][2]*t_mat.m_grid[3][2]+m_grid[3][2]*t_mat.m_grid[3][3];
		var t_m33:Number=m_grid[0][3]*t_mat.m_grid[3][0]+m_grid[1][3]*t_mat.m_grid[3][1]+m_grid[2][3]*t_mat.m_grid[3][2]+m_grid[3][3]*t_mat.m_grid[3][3];
		m_grid[0][0]=t_m00;
		m_grid[0][1]=t_m01;
		m_grid[0][2]=t_m02;
		m_grid[0][3]=t_m03;
		m_grid[1][0]=t_m10;
		m_grid[1][1]=t_m11;
		m_grid[1][2]=t_m12;
		m_grid[1][3]=t_m13;
		m_grid[2][0]=t_m20;
		m_grid[2][1]=t_m21;
		m_grid[2][2]=t_m22;
		m_grid[2][3]=t_m23;
		m_grid[3][0]=t_m30;
		m_grid[3][1]=t_m31;
		m_grid[3][2]=t_m32;
		m_grid[3][3]=t_m33;
	}
	public function p_Multiply42(t_v1:c_Vector):c_Vector{
		var t_v2:c_Vector=(new c_Vector).m_Vector_new(0.0,0.0,0.0);
		t_v2.m_x=m_grid[0][0]*t_v1.m_x+m_grid[1][0]*t_v1.m_y+m_grid[2][0]*t_v1.m_z+m_grid[3][0];
		t_v2.m_y=m_grid[0][1]*t_v1.m_x+m_grid[1][1]*t_v1.m_y+m_grid[2][1]*t_v1.m_z+m_grid[3][1];
		t_v2.m_z=m_grid[0][2]*t_v1.m_x+m_grid[1][2]*t_v1.m_y+m_grid[2][2]*t_v1.m_z+m_grid[3][2];
		return t_v2;
	}
	public function p_ToArray():Array{
		var t_arr:Array=new_number_array(16);
		t_arr[0]=m_grid[0][0];
		t_arr[1]=m_grid[0][1];
		t_arr[2]=m_grid[0][2];
		t_arr[3]=m_grid[0][3];
		t_arr[4]=m_grid[1][0];
		t_arr[5]=m_grid[1][1];
		t_arr[6]=m_grid[1][2];
		t_arr[7]=m_grid[1][3];
		t_arr[8]=m_grid[2][0];
		t_arr[9]=m_grid[2][1];
		t_arr[10]=m_grid[2][2];
		t_arr[11]=m_grid[2][3];
		t_arr[12]=m_grid[3][0];
		t_arr[13]=m_grid[3][1];
		t_arr[14]=m_grid[3][2];
		t_arr[15]=m_grid[3][3];
		return t_arr;
	}
	public function p_ToArray2(t_arr:Array):void{
		t_arr[0]=m_grid[0][0];
		t_arr[1]=m_grid[0][1];
		t_arr[2]=m_grid[0][2];
		t_arr[3]=m_grid[0][3];
		t_arr[4]=m_grid[1][0];
		t_arr[5]=m_grid[1][1];
		t_arr[6]=m_grid[1][2];
		t_arr[7]=m_grid[1][3];
		t_arr[8]=m_grid[2][0];
		t_arr[9]=m_grid[2][1];
		t_arr[10]=m_grid[2][2];
		t_arr[11]=m_grid[2][3];
		t_arr[12]=m_grid[3][0];
		t_arr[13]=m_grid[3][1];
		t_arr[14]=m_grid[3][2];
		t_arr[15]=m_grid[3][3];
	}
	public function p_TransformPoint(t_x:Number,t_y:Number,t_z:Number,t_w:Number):Array{
		var t_p0:Number=.0;
		var t_p1:Number=.0;
		var t_p2:Number=.0;
		var t_p3:Number=.0;
		t_p0=m_grid[0][0]*t_x+m_grid[1][0]*t_y+m_grid[2][0]*t_z+m_grid[3][0]*t_w;
		t_p1=m_grid[0][1]*t_x+m_grid[1][1]*t_y+m_grid[2][1]*t_z+m_grid[3][1]*t_w;
		t_p2=m_grid[0][2]*t_x+m_grid[1][2]*t_y+m_grid[2][2]*t_z+m_grid[3][2]*t_w;
		return [t_p0,t_p1,t_p2];
	}
	public function p_Copy():c_Matrix{
		var t_mat:c_Matrix=(new c_Matrix).m_Matrix_new();
		t_mat.m_grid[0][0]=m_grid[0][0];
		t_mat.m_grid[1][0]=m_grid[1][0];
		t_mat.m_grid[2][0]=m_grid[2][0];
		t_mat.m_grid[3][0]=m_grid[3][0];
		t_mat.m_grid[0][1]=m_grid[0][1];
		t_mat.m_grid[1][1]=m_grid[1][1];
		t_mat.m_grid[2][1]=m_grid[2][1];
		t_mat.m_grid[3][1]=m_grid[3][1];
		t_mat.m_grid[0][2]=m_grid[0][2];
		t_mat.m_grid[1][2]=m_grid[1][2];
		t_mat.m_grid[2][2]=m_grid[2][2];
		t_mat.m_grid[3][2]=m_grid[3][2];
		t_mat.m_grid[0][3]=m_grid[0][3];
		t_mat.m_grid[1][3]=m_grid[1][3];
		t_mat.m_grid[2][3]=m_grid[2][3];
		t_mat.m_grid[3][3]=m_grid[3][3];
		return t_mat;
	}
	public function p_Multiply(t_mat:c_Matrix):void{
		var t_m00:Number=m_grid[0][0]*t_mat.m_grid[0][0]+m_grid[1][0]*t_mat.m_grid[0][1]+m_grid[2][0]*t_mat.m_grid[0][2]+m_grid[3][0]*t_mat.m_grid[0][3];
		var t_m01:Number=m_grid[0][1]*t_mat.m_grid[0][0]+m_grid[1][1]*t_mat.m_grid[0][1]+m_grid[2][1]*t_mat.m_grid[0][2]+m_grid[3][1]*t_mat.m_grid[0][3];
		var t_m02:Number=m_grid[0][2]*t_mat.m_grid[0][0]+m_grid[1][2]*t_mat.m_grid[0][1]+m_grid[2][2]*t_mat.m_grid[0][2]+m_grid[3][2]*t_mat.m_grid[0][3];
		var t_m10:Number=m_grid[0][0]*t_mat.m_grid[1][0]+m_grid[1][0]*t_mat.m_grid[1][1]+m_grid[2][0]*t_mat.m_grid[1][2]+m_grid[3][0]*t_mat.m_grid[1][3];
		var t_m11:Number=m_grid[0][1]*t_mat.m_grid[1][0]+m_grid[1][1]*t_mat.m_grid[1][1]+m_grid[2][1]*t_mat.m_grid[1][2]+m_grid[3][1]*t_mat.m_grid[1][3];
		var t_m12:Number=m_grid[0][2]*t_mat.m_grid[1][0]+m_grid[1][2]*t_mat.m_grid[1][1]+m_grid[2][2]*t_mat.m_grid[1][2]+m_grid[3][2]*t_mat.m_grid[1][3];
		var t_m20:Number=m_grid[0][0]*t_mat.m_grid[2][0]+m_grid[1][0]*t_mat.m_grid[2][1]+m_grid[2][0]*t_mat.m_grid[2][2]+m_grid[3][0]*t_mat.m_grid[2][3];
		var t_m21:Number=m_grid[0][1]*t_mat.m_grid[2][0]+m_grid[1][1]*t_mat.m_grid[2][1]+m_grid[2][1]*t_mat.m_grid[2][2]+m_grid[3][1]*t_mat.m_grid[2][3];
		var t_m22:Number=m_grid[0][2]*t_mat.m_grid[2][0]+m_grid[1][2]*t_mat.m_grid[2][1]+m_grid[2][2]*t_mat.m_grid[2][2]+m_grid[3][2]*t_mat.m_grid[2][3];
		var t_m30:Number=m_grid[0][0]*t_mat.m_grid[3][0]+m_grid[1][0]*t_mat.m_grid[3][1]+m_grid[2][0]*t_mat.m_grid[3][2]+m_grid[3][0]*t_mat.m_grid[3][3];
		var t_m31:Number=m_grid[0][1]*t_mat.m_grid[3][0]+m_grid[1][1]*t_mat.m_grid[3][1]+m_grid[2][1]*t_mat.m_grid[3][2]+m_grid[3][1]*t_mat.m_grid[3][3];
		var t_m32:Number=m_grid[0][2]*t_mat.m_grid[3][0]+m_grid[1][2]*t_mat.m_grid[3][1]+m_grid[2][2]*t_mat.m_grid[3][2]+m_grid[3][2]*t_mat.m_grid[3][3];
		m_grid[0][0]=t_m00;
		m_grid[0][1]=t_m01;
		m_grid[0][2]=t_m02;
		m_grid[1][0]=t_m10;
		m_grid[1][1]=t_m11;
		m_grid[1][2]=t_m12;
		m_grid[2][0]=t_m20;
		m_grid[2][1]=t_m21;
		m_grid[2][2]=t_m22;
		m_grid[3][0]=t_m30;
		m_grid[3][1]=t_m31;
		m_grid[3][2]=t_m32;
	}
	public function p_Multiply2(t_v1:c_Vector):c_Vector{
		var t_v2:c_Vector=(new c_Vector).m_Vector_new(0.0,0.0,0.0);
		t_v2.m_x=m_grid[0][0]*t_v1.m_x+m_grid[1][0]*t_v1.m_y+m_grid[2][0]*t_v1.m_z;
		t_v2.m_y=m_grid[0][1]*t_v1.m_x+m_grid[1][1]*t_v1.m_y+m_grid[2][1]*t_v1.m_z;
		t_v2.m_z=m_grid[0][2]*t_v1.m_x+m_grid[1][2]*t_v1.m_y+m_grid[2][2]*t_v1.m_z;
		return t_v2;
	}
	public function p_Multiply3(t_q:c_Line):c_Line{
		var t_t:c_Vector=this.p_Multiply2(t_q.m_o);
		return (new c_Line).m_Line_new2(t_t,this.p_Multiply2(t_q.m_o.p_Add(t_q.m_d)).p_Subtract(t_t));
	}
	public function p_CreateMatrix(t_rx:Number,t_ry:Number,t_rz:Number,t_scx:Number,t_scy:Number,t_scz:Number,t_px:Number,t_py:Number,t_pz:Number):void{
		var t_sx:Number=.0;
		var t_sy:Number=.0;
		var t_sz:Number=.0;
		var t_cx:Number=.0;
		var t_cy:Number=.0;
		var t_cz:Number=.0;
		var t_theta:Number=.0;
		t_sx=Math.sin((t_rx)*D2R);
		t_cx=Math.cos((t_rx)*D2R);
		t_sy=Math.sin((t_ry)*D2R);
		t_cy=Math.cos((t_ry)*D2R);
		t_sz=Math.sin((t_rz)*D2R);
		t_cz=Math.cos((t_rz)*D2R);
		var t_sycz:Number=t_sy*t_cz;
		var t_cysz:Number=t_cy*t_sz;
		var t_sysz:Number=t_sy*t_sz;
		var t_cycz:Number=t_cy*t_cz;
		m_grid[0][0]=(t_cycz+t_sysz*t_sx)*t_scx;
		m_grid[0][1]=t_cx*t_sz*t_scx;
		m_grid[0][2]=(-t_sycz+t_cysz*t_sx)*t_scx;
		m_grid[0][3]=0.0;
		m_grid[1][0]=(-t_cysz+t_sycz*t_sx)*t_scy;
		m_grid[1][1]=t_cx*t_cz*t_scy;
		m_grid[1][2]=(t_sysz+t_cycz*t_sx)*t_scy;
		m_grid[1][3]=0.0;
		m_grid[2][0]=t_sy*t_cx*t_scz;
		m_grid[2][1]=-t_sx*t_scz;
		m_grid[2][2]=t_cx*t_cy*t_scz;
		m_grid[2][3]=0.0;
		m_grid[3][0]=t_px;
		m_grid[3][1]=t_py;
		m_grid[3][2]=t_pz;
		m_grid[3][3]=1.0;
	}
	public function p_FastRotateScale(t_rx:Number,t_ry:Number,t_rz:Number,t_scx:Number,t_scy:Number,t_scz:Number):void{
		this.p_CreateMatrix(t_rx,t_ry,t_rz,t_scx,t_scy,t_scz,m_grid[3][0],m_grid[3][1],m_grid[3][2]);
	}
	internal static var m_temp:c_Matrix;
	public function p_Transpose():c_Matrix{
		m_temp.p_Overwrite(this);
		m_grid[0][0]=m_temp.m_grid[0][0];
		m_grid[1][0]=m_temp.m_grid[0][1];
		m_grid[2][0]=m_temp.m_grid[0][2];
		m_grid[3][0]=m_temp.m_grid[0][3];
		m_grid[0][1]=m_temp.m_grid[1][0];
		m_grid[1][1]=m_temp.m_grid[1][1];
		m_grid[2][1]=m_temp.m_grid[1][2];
		m_grid[3][1]=m_temp.m_grid[1][3];
		m_grid[0][2]=m_temp.m_grid[2][0];
		m_grid[1][2]=m_temp.m_grid[2][1];
		m_grid[2][2]=m_temp.m_grid[2][2];
		m_grid[3][2]=m_temp.m_grid[2][3];
		m_grid[0][3]=m_temp.m_grid[3][0];
		m_grid[1][3]=m_temp.m_grid[3][1];
		m_grid[2][3]=m_temp.m_grid[3][2];
		m_grid[3][3]=m_temp.m_grid[3][3];
		return this;
	}
	public function p_RotateRoll(t_ang:Number):void{
		var t_cos_ang:Number=Math.cos((t_ang)*D2R);
		var t_sin_ang:Number=Math.sin((t_ang)*D2R);
		var t_m00:Number=m_grid[0][0]*t_cos_ang+m_grid[1][0]*t_sin_ang;
		var t_m01:Number=m_grid[0][1]*t_cos_ang+m_grid[1][1]*t_sin_ang;
		var t_m02:Number=m_grid[0][2]*t_cos_ang+m_grid[1][2]*t_sin_ang;
		m_grid[1][0]=m_grid[0][0]*-t_sin_ang+m_grid[1][0]*t_cos_ang;
		m_grid[1][1]=m_grid[0][1]*-t_sin_ang+m_grid[1][1]*t_cos_ang;
		m_grid[1][2]=m_grid[0][2]*-t_sin_ang+m_grid[1][2]*t_cos_ang;
		m_grid[0][0]=t_m00;
		m_grid[0][1]=t_m01;
		m_grid[0][2]=t_m02;
	}
}
class c_Vector extends Object{
	internal var m_x:Number=.0;
	internal var m_y:Number=.0;
	internal var m_z:Number=.0;
	public function m_Vector_new(t_xx:Number,t_yy:Number,t_zz:Number):c_Vector{
		m_x=t_xx;
		m_y=t_yy;
		m_z=t_zz;
		return this;
	}
	public function p_Copy():c_Vector{
		return (new c_Vector).m_Vector_new(m_x,m_y,m_z);
	}
	public function p_Add(t_vec:c_Vector):c_Vector{
		return (new c_Vector).m_Vector_new(m_x+t_vec.m_x,m_y+t_vec.m_y,m_z+t_vec.m_z);
	}
	public function p_Add2(t_vx:Number,t_vy:Number,t_vz:Number):c_Vector{
		return (new c_Vector).m_Vector_new(m_x+t_vx,m_y+t_vy,m_z+t_vz);
	}
	public function p_Subtract(t_vec:c_Vector):c_Vector{
		return (new c_Vector).m_Vector_new(m_x-t_vec.m_x,m_y-t_vec.m_y,m_z-t_vec.m_z);
	}
	public function p_Subtract2(t_vx:Number,t_vy:Number,t_vz:Number):c_Vector{
		return (new c_Vector).m_Vector_new(m_x-t_vx,m_y-t_vy,m_z-t_vz);
	}
	public function p_Normalize():c_Vector{
		if(m_x==0.0 && m_y==0.0 && m_z==0.0){
			return (new c_Vector).m_Vector_new(0.0,0.0,0.0);
		}
		var t_d:Number=1.0/Math.sqrt(m_x*m_x+m_y*m_y+m_z*m_z);
		return (new c_Vector).m_Vector_new(m_x*t_d,m_y*t_d,m_z*t_d);
	}
}
class c_TCollision extends Object{
	public function m_TCollision_new():c_TCollision{
		return this;
	}
	internal var m_updated_shape:Boolean=false;
}
class c_List extends Object{
	public function m_List_new():c_List{
		return this;
	}
	internal var m__head:c_Node2=((new c_HeadNode).m_HeadNode_new());
	public function p_AddLast(t_data:c_TEntity):c_Node2{
		return (new c_Node2).m_Node_new(m__head,m__head.m__pred,t_data);
	}
	public function m_List_new2(t_data:Array):c_List{
		var t_:Array=t_data;
		var t_2:int=0;
		while(t_2<t_.length){
			var t_t:c_TEntity=t_[t_2];
			t_2=t_2+1;
			this.p_AddLast(t_t);
		}
		return this;
	}
	public function p_FirstNode():c_Node2{
		if(m__head.m__succ!=m__head){
			return m__head.m__succ;
		}
		return null;
	}
	public function p_AddFirst(t_data:c_TEntity):c_Node2{
		return (new c_Node2).m_Node_new(m__head.m__succ,m__head,t_data);
	}
	public function p_ObjectEnumerator():c_Enumerator7{
		return (new c_Enumerator7).m_Enumerator_new(this);
	}
	public function p_IsEmpty():Boolean{
		return m__head.m__succ==m__head;
	}
}
class c_EntityList extends c_List{
	public function m_EntityList_new():c_EntityList{
		super.m_List_new();
		return this;
	}
	public function p_EntityListAdd(t_obj:c_TEntity):c_Node2{
		var t_llink:c_Node2=this.p_FirstNode();
		if(t_obj.m_order>0){
			t_llink=this.p_AddFirst(t_obj);
			return t_llink;
		}else{
			t_llink=this.p_AddLast(t_obj);
			return t_llink;
		}
		return null;
	}
}
class c_Node2 extends Object{
	internal var m__succ:c_Node2=null;
	internal var m__pred:c_Node2=null;
	internal var m__data:c_TEntity=null;
	public function m_Node_new(t_succ:c_Node2,t_pred:c_Node2,t_data:c_TEntity):c_Node2{
		m__succ=t_succ;
		m__pred=t_pred;
		m__succ.m__pred=this;
		m__pred.m__succ=this;
		m__data=t_data;
		return this;
	}
	public function m_Node_new2():c_Node2{
		return this;
	}
	public function p_Remove():int{
		m__succ.m__pred=m__pred;
		m__pred.m__succ=m__succ;
		return 0;
	}
}
class c_HeadNode extends c_Node2{
	public function m_HeadNode_new():c_HeadNode{
		super.m_Node_new2();
		m__succ=(this);
		m__pred=(this);
		return this;
	}
}
internal function bb_functions_CreateMesh(t_parent:c_TEntity):c_TMesh{
	return c_TMesh.m_CreateMesh(t_parent);
}
class c_TBrush extends Object{
	public function m_TBrush_new():c_TBrush{
		return this;
	}
	internal var m_red:Number=1.0;
	internal var m_green:Number=1.0;
	internal var m_blue:Number=1.0;
	internal var m_tex:Array=new_object_array(8);
	public function m_TBrush_new2(t_hexcolor:int):c_TBrush{
		m_red=((t_hexcolor&16711680)>>16)*0.0039215686274509803;
		m_green=((t_hexcolor&65280)>>8)*0.0039215686274509803;
		m_blue=(t_hexcolor&255)*0.0039215686274509803;
		m_tex[0]=(new c_TTexture).m_TTexture_new();
		return this;
	}
	public function m_TBrush_new3(t_r:int,t_g:int,t_b:int):c_TBrush{
		m_red=(t_r)*0.0039215686274509803;
		m_green=(t_g)*0.0039215686274509803;
		m_blue=(t_b)*0.0039215686274509803;
		m_tex[0]=(new c_TTexture).m_TTexture_new();
		return this;
	}
	internal var m_no_texs:int=0;
	public function p_BrushTexture(t_texture:c_TTexture,t_frame:int,t_index:int):void{
		m_tex[t_index]=t_texture;
		if(t_index+1>m_no_texs){
			m_no_texs=t_index+1;
		}
		if(t_frame<0){
			t_frame=0;
		}
		if(t_frame>t_texture.m_no_frames-1){
			t_frame=t_texture.m_no_frames-1;
		}
		t_texture.m_tex_frame=t_frame;
		if(t_frame>0 && t_texture.m_no_frames>1){
			var t_x:int=t_frame % t_texture.m_frame_xstep;
			var t_y:int=((t_frame/t_texture.m_frame_ystep)|0) % t_texture.m_frame_ystep;
			t_texture.m_u_pos=(t_x)*t_texture.m_frame_ustep;
			t_texture.m_v_pos=(t_y)*t_texture.m_frame_vstep;
		}
	}
	public function m_TBrush_new4(t_texture:c_TTexture):c_TBrush{
		this.p_BrushTexture(t_texture,0,0);
		return this;
	}
	internal var m_fx:int=0;
	internal var m_name:String="";
	internal var m_alpha:Number=1.0;
	internal var m_shine:Number=0.05;
	internal var m_shine_strength:Number=100.0;
	internal var m_blend:int=0;
	public function p_Copy():c_TBrush{
		var t_brush:c_TBrush=(new c_TBrush).m_TBrush_new();
		t_brush.m_no_texs=m_no_texs;
		t_brush.m_name=m_name;
		t_brush.m_red=m_red;
		t_brush.m_green=m_green;
		t_brush.m_blue=m_blue;
		t_brush.m_alpha=m_alpha;
		t_brush.m_shine=m_shine;
		t_brush.m_shine_strength=m_shine_strength;
		t_brush.m_blend=m_blend;
		t_brush.m_fx=m_fx;
		if((m_tex[0])!=null){
			t_brush.m_tex[0]=m_tex[0];
		}
		if((m_tex[1])!=null){
			t_brush.m_tex[1]=m_tex[1];
		}
		if((m_tex[2])!=null){
			t_brush.m_tex[2]=m_tex[2];
		}
		if((m_tex[3])!=null){
			t_brush.m_tex[3]=m_tex[3];
		}
		if((m_tex[4])!=null){
			t_brush.m_tex[4]=m_tex[4];
		}
		if((m_tex[5])!=null){
			t_brush.m_tex[5]=m_tex[5];
		}
		if((m_tex[6])!=null){
			t_brush.m_tex[6]=m_tex[6];
		}
		if((m_tex[7])!=null){
			t_brush.m_tex[7]=m_tex[7];
		}
		return t_brush;
	}
	public function p_GetTexture(t_index:int):c_TTexture{
		return m_tex[t_index];
	}
}
class c_TTexture extends Object{
	internal static var m_useGlobalResizeSmooth:Boolean;
	internal var m_resize_smooth:Boolean=false;
	public function m_TTexture_new():c_TTexture{
		m_resize_smooth=m_useGlobalResizeSmooth;
		return this;
	}
	internal var m_no_frames:int=1;
	internal var m_tex_frame:int=0;
	internal var m_frame_xstep:int=0;
	internal var m_frame_ystep:int=0;
	internal var m_frame_ustep:Number=1.0;
	internal var m_u_pos:Number=.0;
	internal var m_frame_vstep:Number=1.0;
	internal var m_v_pos:Number=.0;
	internal static var m_tex_bind_stack:c_TextureStack;
	internal var m_bind_flags:int=-1;
	internal var m_tex_link:c_Node6=null;
	internal var m_pixmap:c_TPixmap=null;
	internal var m_file:String="";
	internal var m_gltex:Array=new_number_array(1);
	public function p_FreeTexture_():int{
		m_tex_link.p_Remove();
		if((m_pixmap)!=null){
			m_pixmap.p_DecBind();
			if(m_pixmap.p_GetBindCount()==0){
				c_TPixmap.m_preloader.p_RemoveFromStack(m_file);
				m_pixmap.p_FreePixmap();
			}
		}
		m_gltex[0]=0;
		return 0;
	}
	internal var m_freeMemoryAfterBind:Boolean=false;
	internal var m_flags:int=0;
	public function p_FilterFlags():int{
		var t_:c_Enumerator10=c_TTextureFilter.m_filter_list.p_ObjectEnumerator();
		while(t_.p_HasNext()){
			var t_filter:c_TTextureFilter=t_.p_NextObject();
			var t_len1:int=t_filter.m_text.length;
			var t_len2:int=m_file.length-t_len1;
			var t_file2:String=m_file.slice(t_len2);
			if(t_file2==t_filter.m_text){
				m_flags=m_flags|t_filter.m_flags;
			}
		}
		return 0;
	}
	internal static var m_tex_list:c_List12;
	public function p_TexInList():c_TTexture{
		var t_:c_Enumerator11=m_tex_list.p_ObjectEnumerator();
		while(t_.p_HasNext()){
			var t_tex:c_TTexture=t_.p_NextObject();
			if(m_file==t_tex.m_file && m_flags==t_tex.m_flags){
				return t_tex;
			}
		}
		return null;
	}
	internal var m_orig_width:int=0;
	internal var m_orig_height:int=0;
	public static function m_Pow2Size(t_n:int):int{
		var t_t:int=1;
		while(t_t<t_n){
			t_t=t_t<<1;
		}
		return t_t;
	}
	public static function m_AdjustPixmap(t_pixmap:c_TPixmap,t_resize_smooth:Boolean,t_tex:c_TTexture):c_TPixmap{
		var t_width:int=m_Pow2Size(t_pixmap.m_width);
		var t_height:int=m_Pow2Size(t_pixmap.m_height);
		if(t_width!=t_pixmap.m_width || t_height!=t_pixmap.m_height){
			if(t_resize_smooth){
				t_pixmap=t_pixmap.p_ResizePixmap(t_width,t_height);
			}else{
				t_pixmap=t_pixmap.p_ResizePixmapNoSmooth(t_width,t_height);
			}
		}
		return t_pixmap;
	}
	internal var m_width:int=0;
	internal var m_height:int=0;
	internal var m_frame_startx:int=0;
	internal var m_frame_starty:int=0;
	internal var m_u_scale:Number=1.0;
	internal var m_v_scale:Number=1.0;
	public function p_SetAnimationFrames(t_first_frame:int,t_frame_count:int,t_frame_width:int,t_frame_height:int):void{
		m_frame_xstep=((m_pixmap.m_width/t_frame_width)|0);
		m_frame_ystep=((m_pixmap.m_height/t_frame_height)|0);
		m_frame_startx=t_first_frame % m_frame_xstep;
		m_frame_starty=((t_first_frame/m_frame_ystep)|0) % m_frame_ystep;
		if(t_frame_count<0){
			t_frame_count=m_frame_xstep*m_frame_ystep;
		}
		m_no_frames=t_frame_count;
		if(m_no_frames>1){
			m_frame_ustep=1.0/(m_frame_xstep);
			m_frame_vstep=1.0/(m_frame_ystep);
			m_u_scale=m_frame_ustep;
			m_v_scale=m_frame_vstep;
			m_u_pos=(m_frame_startx)*m_frame_ustep;
			m_v_pos=(m_frame_starty)*m_frame_vstep;
		}
	}
	public static function m_PushBindTexture(t_tex:c_TTexture,t_flags:int):int{
		t_tex.m_bind_flags=t_flags;
		m_tex_bind_stack.p_Push7(t_tex);
		return 0;
	}
	public static function m_LoadAnimTexture(t_file:String,t_flags:int,t_frame_width:int,t_frame_height:int,t_first_frame:int,t_frame_count:int,t_tex:c_TTexture,t_force_new:int):c_TTexture{
		if(t_tex==null){
			t_tex=(new c_TTexture).m_TTexture_new();
		}
		t_tex.m_file=t_file;
		t_tex.p_FilterFlags();
		if(t_flags>-1){
			t_tex.m_flags=t_flags;
		}
		var t_old_tex:c_TTexture=null;
		if(!((t_force_new)!=0)){
			t_old_tex=t_tex.p_TexInList();
		}
		if(t_old_tex!=null && t_old_tex!=t_tex){
			return t_old_tex;
		}else{
			if(t_old_tex!=t_tex){
				t_tex.m_tex_link=m_tex_list.p_AddLast12(t_tex);
			}
		}
		var t_new_scx:Number=1.0;
		var t_new_scy:Number=1.0;
		var t_oldw:int=0;
		var t_oldh:int=0;
		t_tex.m_pixmap=c_TPixmap.m_LoadPixmap(t_file);
		if(t_tex.m_pixmap.m_height==0){
			return t_tex;
		}
		t_oldw=t_tex.m_pixmap.m_width;
		t_oldh=t_tex.m_pixmap.m_height;
		t_tex.m_orig_width=t_oldw;
		t_tex.m_orig_height=t_oldh;
		if((t_tex.m_flags&256)==0){
			t_tex.m_pixmap=m_AdjustPixmap(t_tex.m_pixmap,t_tex.m_resize_smooth,t_tex);
		}
		t_tex.m_width=t_tex.m_pixmap.m_width;
		t_tex.m_height=t_tex.m_pixmap.m_height;
		if(t_oldw!=t_tex.m_width || t_oldh!=t_tex.m_height){
			t_new_scx=(t_tex.m_width)/(t_oldw);
			t_new_scy=(t_tex.m_height)/(t_oldh);
		}
		if(t_frame_width==0 && t_frame_height==0){
			t_frame_width=t_tex.m_pixmap.m_width;
			t_frame_height=t_tex.m_pixmap.m_height;
		}else{
			t_frame_width=(((t_frame_width)*t_new_scx)|0);
			t_frame_height=(((t_frame_height)*t_new_scy)|0);
		}
		t_tex.p_SetAnimationFrames(t_first_frame,t_frame_count,t_frame_width,t_frame_height);
		m_PushBindTexture(t_tex,t_flags);
		return t_tex;
	}
	public static function m_LoadTexture(t_file:String,t_flags:int,t_tex:c_TTexture):c_TTexture{
		return m_LoadAnimTexture(t_file,t_flags,0,0,0,1,t_tex,0);
	}
	public static function m_LoadTexture2(t_pixmap:c_TPixmap,t_flags:int,t_tex:c_TTexture):c_TTexture{
		if(!((t_tex)!=null)){
			t_tex=(new c_TTexture).m_TTexture_new();
			t_tex.m_tex_link=m_tex_list.p_AddLast12(t_tex);
		}
		t_tex.p_FilterFlags();
		if(t_flags>-1){
			t_tex.m_flags=t_flags;
		}
		if(t_pixmap==null){
			return t_tex;
		}
		t_tex.m_pixmap=t_pixmap;
		if(t_tex.m_pixmap.m_height==0){
			return t_tex;
		}
		if((t_tex.m_flags&256)==0){
			t_tex.m_pixmap=m_AdjustPixmap(t_tex.m_pixmap,t_tex.m_resize_smooth,t_tex);
		}
		t_tex.m_width=t_tex.m_pixmap.m_width;
		t_tex.m_height=t_tex.m_pixmap.m_height;
		m_PushBindTexture(t_tex,t_flags);
		return t_tex;
	}
	internal var m_is_font:Boolean=false;
	internal var m_blend:int=2;
	public function p_TextureBlend(t_blend_no:int):int{
		m_blend=t_blend_no;
		return 0;
	}
	public static function m_CreateTexture(t_width:int,t_height:int,t_flags:int,t_frames:int,t_tex:c_TTexture):c_TTexture{
		if(t_tex==null){
			t_tex=(new c_TTexture).m_TTexture_new();
			t_tex.m_tex_link=m_tex_list.p_AddLast12(t_tex);
		}
		t_width=m_Pow2Size(t_width);
		t_height=m_Pow2Size(t_height);
		t_tex.m_pixmap=c_TPixmap.m_CreatePixmap(t_width*t_frames,t_height,4);
		t_tex.m_flags=t_flags;
		t_tex.m_no_frames=t_frames;
		t_tex.m_gltex=t_tex.m_gltex.slice(0,t_tex.m_no_frames);
		var t_pixmap:c_TPixmap=t_tex.m_pixmap;
		if((t_tex.m_flags&256)==0){
			t_pixmap=m_AdjustPixmap(t_pixmap,t_tex.m_resize_smooth,t_tex);
		}
		t_tex.m_width=t_pixmap.m_width;
		t_tex.m_height=t_pixmap.m_height;
		t_tex.m_orig_width=t_tex.m_width;
		t_tex.m_orig_height=t_tex.m_height;
		m_PushBindTexture(t_tex,t_flags);
		return t_tex;
	}
	internal var m_coords:int=0;
	internal var m_angle:Number=.0;
	internal var m_cube_mode:int=1;
	internal var m_tex_smooth:Boolean=true;
	internal var m_tex_id:int=0;
	public static function m_TextureFilter(t_match_text:String,t_flags:int):int{
		var t_filter:c_TTextureFilter=(new c_TTextureFilter).m_TTextureFilter_new();
		t_filter.m_text=t_match_text;
		t_filter.m_flags=t_flags;
		c_TTextureFilter.m_filter_list.p_AddLast11(t_filter);
		return 0;
	}
	internal var m_no_mipmaps:int=0;
	public function p_ResizeNoSmooth():int{
		m_resize_smooth=false;
		return 0;
	}
	public function p_FreeTexture():int{
		m_PushBindTexture(this,-255);
		return 0;
	}
}
class c_TSurface extends Object{
	public function m_TSurface_new():c_TSurface{
		return this;
	}
	internal var m_brush:c_TBrush=(new c_TBrush).m_TBrush_new();
	internal var m_surf_id:int=0;
	internal var m_no_verts:int=0;
	internal var m_no_tris:int=0;
	internal var m_vbo_dyn:Boolean=false;
	internal var m_vert_data:c_VertexDataBuffer=(new c_VertexDataBuffer).m_VertexDataBuffer_new();
	internal var m_alpha_enable:Boolean=false;
	internal var m_vert_array_size:int=1;
	public function p_AddVertex(t_x:Number,t_y:Number,t_z:Number,t_u:Number,t_v:Number,t_w:Number):int{
		m_no_verts=m_no_verts+1;
		if(m_no_verts>=m_vert_array_size){
			do{
				m_vert_array_size=m_vert_array_size+512;
			}while(!(m_vert_array_size>m_no_verts));
			var t_vas:int=m_vert_array_size;
			m_vert_data=bb_monkeybuffer_CopyDataBuffer2(m_vert_data,c_VertexDataBuffer.m_Create(t_vas));
		}
		var t_vid:int=m_no_verts-1;
		var t_data:Array=[t_x,t_y,-t_z,0.0,1.0,1.0,1.0,0.0,1.0,1.0,1.0,1.0,t_u,t_v,t_u,t_v];
		m_vert_data.p_PokeFloatArray(t_vid,t_data,-1);
		return t_vid;
	}
	public function p_AddVertex2(t_data:Array,t_len:int):int{
		if(t_len==-1){
			t_len=t_data.length;
		}
		var t_total:int=t_len>>4;
		var t_vid:int=m_no_verts;
		m_no_verts=m_no_verts+t_total;
		if(m_no_verts>=m_vert_array_size){
			do{
				m_vert_array_size=m_vert_array_size+512;
			}while(!(m_vert_array_size>m_no_verts));
			var t_vas:int=m_vert_array_size;
			m_vert_data=bb_monkeybuffer_CopyDataBuffer2(m_vert_data,c_VertexDataBuffer.m_Create(t_vas));
		}
		m_vert_data.p_PokeFloatArray(t_vid,t_data,t_len);
		return t_vid+(t_total-1);
	}
	internal var m_tri_array_size:int=1;
	internal var m_tris:c_ShortBuffer=(new c_ShortBuffer).m_ShortBuffer_new();
	internal var m_reset_vbo:int=-1;
	public function p_AddTriangle(t_v0:int,t_v1:int,t_v2:int):int{
		m_no_tris=m_no_tris+1;
		if(m_no_tris>=m_tri_array_size){
			do{
				m_tri_array_size=m_tri_array_size+512;
			}while(!(m_tri_array_size>m_no_tris));
			var t_tas:int=m_tri_array_size;
			m_tris=bb_monkeybuffer_CopyShortBuffer(m_tris,c_ShortBuffer.m_Create(t_tas*3));
		}
		var t_v0i:int=m_no_tris*3-3;
		var t_v1i:int=m_no_tris*3-2;
		var t_v2i:int=m_no_tris*3-1;
		m_tris.p_Poke(t_v0i,[t_v2,t_v1,t_v0],-1);
		m_reset_vbo=-1;
		return m_no_tris;
	}
	public function p_AddTriangle2(t_arr:Array,t_len:int):int{
		if(t_len==-1){
			t_len=t_arr.length;
		}
		var t_t0:int=m_no_tris*3;
		m_no_tris=m_no_tris+((t_len/3)|0);
		if(m_no_tris>=m_tri_array_size){
			do{
				m_tri_array_size=m_tri_array_size+512;
			}while(!(m_tri_array_size>m_no_tris));
			var t_tas:int=m_tri_array_size;
			m_tris=bb_monkeybuffer_CopyShortBuffer(m_tris,c_ShortBuffer.m_Create(t_tas*3));
		}
		var t_temp:int=0;
		for(var t_t:int=0;t_t<=t_len-1;t_t=t_t+3){
			t_temp=t_arr[t_t];
			t_arr[t_t]=t_arr[t_t+2];
			t_arr[t_t+2]=t_temp;
		}
		m_tris.p_Poke(t_t0,t_arr,t_len);
		m_reset_vbo=-1;
		return m_no_tris;
	}
	public function p_VertexNormal(t_vid:int,t_nx:Number,t_ny:Number,t_nz:Number):int{
		m_vert_data.p_PokeNormals(t_vid,t_nx,t_ny,-t_nz);
		m_reset_vbo=m_reset_vbo|4;
		return 0;
	}
	public function p_VertexTexCoords(t_vid:int,t_u:Number,t_v:Number,t_w:Number,t_coord_set:int):int{
		if(t_coord_set==0){
			m_vert_data.p_PokeTexCoords0(t_vid,t_u,t_v);
		}else{
			if(t_coord_set==1){
				m_vert_data.p_PokeTexCoords1(t_vid,t_u,t_v);
			}
		}
		m_reset_vbo=m_reset_vbo|2;
		return 0;
	}
	public function p_CropSurfaceBuffers():int{
		if(m_no_verts<1 && m_no_tris<1){
			return 0;
		}
		m_vert_data=bb_monkeybuffer_CopyDataBuffer2(m_vert_data,c_VertexDataBuffer.m_Create(m_no_verts));
		m_tris=bb_monkeybuffer_CopyShortBuffer(m_tris,c_ShortBuffer.m_Create(m_no_tris*3));
		m_vert_array_size=m_no_verts;
		m_tri_array_size=m_no_tris;
		return 0;
	}
	public function p_ClearSurface(t_clear_verts:Boolean,t_clear_tris:Boolean,t_keep_array:Boolean):int{
		if(t_clear_verts){
			m_no_verts=0;
			if(!t_keep_array){
				m_vert_data=c_VertexDataBuffer.m_Create(0);
				m_vert_array_size=1;
			}
		}
		if(t_clear_tris){
			m_no_tris=0;
			if(!t_keep_array){
				m_tris=c_ShortBuffer.m_Create(0);
				m_tri_array_size=1;
			}
		}
		m_reset_vbo=-1;
		return 0;
	}
	public function p_TriangleVertex(t_tri_no:int,t_corner:int):int{
		return m_tris.p_Peek(t_tri_no*3+(2-t_corner));
	}
	public function p_UpdateNormals(t_create_only:Boolean):int{
		var t_norm_map:c_NormMap=(new c_NormMap).m_NormMap_new();
		for(var t_t:int=0;t_t<=m_no_tris-1;t_t=t_t+1){
			var t_tri_no:int=(t_t+1)*3;
			var t_v0:int=m_tris.p_Peek(t_tri_no-3);
			var t_v1:int=m_tris.p_Peek(t_tri_no-2);
			var t_v2:int=m_tris.p_Peek(t_tri_no-1);
			var t_ax:Number=m_vert_data.p_VertexX(t_v1)-m_vert_data.p_VertexX(t_v0);
			var t_ay:Number=m_vert_data.p_VertexY(t_v1)-m_vert_data.p_VertexY(t_v0);
			var t_az:Number=m_vert_data.p_VertexZ(t_v1)-m_vert_data.p_VertexZ(t_v0);
			var t_bx:Number=m_vert_data.p_VertexX(t_v2)-m_vert_data.p_VertexX(t_v1);
			var t_by:Number=m_vert_data.p_VertexY(t_v2)-m_vert_data.p_VertexY(t_v1);
			var t_bz:Number=m_vert_data.p_VertexZ(t_v2)-m_vert_data.p_VertexZ(t_v1);
			var t_nx:Number=t_ay*t_bz-t_az*t_by;
			var t_ny:Number=t_az*t_bx-t_ax*t_bz;
			var t_nz:Number=t_ax*t_by-t_ay*t_bx;
			var t_norm:c_Vector=(new c_Vector).m_Vector_new(t_nx,t_ny,t_nz);
			var t_vnorm:c_Vector=null;
			var t_vx:c_Vector=null;
			var t_new_norm:c_Vector=null;
			var t_vhelper:c_NormHelperClass=null;
			for(var t_c:int=0;t_c<=2;t_c=t_c+1){
				var t_v:int=this.p_TriangleVertex(t_t,t_c);
				t_vx=m_vert_data.p_PeekVertCoords(t_v);
				t_vhelper=t_norm_map.p_Get3(t_vx);
				if(!((t_vhelper)!=null)){
					t_vhelper=(new c_NormHelperClass).m_NormHelperClass_new();
					t_vhelper.m_vec=(new c_Vector).m_Vector_new(0.0,0.0,0.0);
					t_vhelper.m_vert=t_v;
				}
				t_vhelper.m_vec=t_norm.p_Add(t_vhelper.m_vec);
				if(!t_create_only){
					t_norm_map.p_Set2(t_vx,t_vhelper);
				}
			}
		}
		for(var t_v3:int=0;t_v3<=m_no_verts-1;t_v3=t_v3+1){
			var t_vx2:c_Vector=m_vert_data.p_PeekVertCoords(t_v3);
			var t_norm2:c_NormHelperClass=t_norm_map.p_Get3(t_vx2);
			if((t_norm2)!=null){
				t_norm2.m_vec=t_norm2.m_vec.p_Normalize();
				m_vert_data.p_PokeNormals(t_v3,t_norm2.m_vec.m_x,t_norm2.m_vec.m_y,t_norm2.m_vec.m_z);
			}
		}
		m_reset_vbo=m_reset_vbo|4;
		return 0;
	}
	internal var m_vbo_id:Array=[0,0,0,0,0,0,0];
	internal var m_vert_anim:Array=[];
	internal var m_anim_frame:int=0;
	public function p_VertexCoords(t_vid:int,t_x:Number,t_y:Number,t_z:Number):int{
		m_vert_data.p_PokeVertCoords(t_vid,t_x,t_y,-t_z);
		m_reset_vbo=m_reset_vbo|1;
		return 0;
	}
	public function p_VertexColor(t_vid:int,t_r:Number,t_g:Number,t_b:Number,t_a:Number):int{
		m_vert_data.p_PokeColor(t_vid,t_r*0.0039215686274509803,t_g*0.0039215686274509803,t_b*0.0039215686274509803,t_a);
		m_reset_vbo=m_reset_vbo|8;
		return 0;
	}
	public function p_PaintSurface(t_bru:c_TBrush):int{
		if(m_brush==null){
			m_brush=(new c_TBrush).m_TBrush_new();
		}
		m_brush.m_no_texs=t_bru.m_no_texs;
		m_brush.m_name=t_bru.m_name;
		m_brush.m_red=t_bru.m_red;
		m_brush.m_green=t_bru.m_green;
		m_brush.m_blue=t_bru.m_blue;
		m_brush.m_alpha=t_bru.m_alpha;
		m_brush.m_shine=t_bru.m_shine;
		m_brush.m_blend=t_bru.m_blend;
		m_brush.m_fx=t_bru.m_fx;
		for(var t_i:int=0;t_i<=7;t_i=t_i+1){
			m_brush.m_tex[t_i]=t_bru.m_tex[t_i];
		}
		return 0;
	}
	public function p_PaintSurface2(t_tex:c_TTexture,t_index:int):int{
		if(m_brush==null){
			m_brush=(new c_TBrush).m_TBrush_new();
		}
		m_brush.m_no_texs=bb_math2_Max(m_brush.m_no_texs,t_index+1);
		m_brush.m_tex[t_index]=t_tex;
		return 0;
	}
}
class c_List2 extends Object{
	public function m_List_new():c_List2{
		return this;
	}
	internal var m__head:c_Node3=((new c_HeadNode2).m_HeadNode_new());
	public function p_AddLast2(t_data:c_TSurface):c_Node3{
		return (new c_Node3).m_Node_new(m__head,m__head.m__pred,t_data);
	}
	public function m_List_new2(t_data:Array):c_List2{
		var t_:Array=t_data;
		var t_2:int=0;
		while(t_2<t_.length){
			var t_t:c_TSurface=t_[t_2];
			t_2=t_2+1;
			this.p_AddLast2(t_t);
		}
		return this;
	}
	public function p_Clear():int{
		m__head.m__succ=m__head;
		m__head.m__pred=m__head;
		return 0;
	}
	public function p_ObjectEnumerator():c_Enumerator8{
		return (new c_Enumerator8).m_Enumerator_new(this);
	}
}
class c_Node3 extends Object{
	internal var m__succ:c_Node3=null;
	internal var m__pred:c_Node3=null;
	internal var m__data:c_TSurface=null;
	public function m_Node_new(t_succ:c_Node3,t_pred:c_Node3,t_data:c_TSurface):c_Node3{
		m__succ=t_succ;
		m__pred=t_pred;
		m__succ.m__pred=this;
		m__pred.m__succ=this;
		m__data=t_data;
		return this;
	}
	public function m_Node_new2():c_Node3{
		return this;
	}
}
class c_HeadNode2 extends c_Node3{
	public function m_HeadNode_new():c_HeadNode2{
		super.m_Node_new2();
		m__succ=(this);
		m__pred=(this);
		return this;
	}
}
class c_TColTree extends Object{
	public function m_TColTree_new():c_TColTree{
		return this;
	}
	internal var m_reset_col_tree:int=0;
}
class c_MojoSurface extends EmptyNullClass{
	public function m_MojoSurface_new():c_MojoSurface{
		return this;
	}
	internal var m_tex:c_TTexture=null;
	internal var m_path:String="";
	public static function m_Create(t_path:String):c_MojoSurface{
		var t_s:c_MojoSurface=(new c_MojoSurface).m_MojoSurface_new();
		t_s.m_tex=bb_functions_CreateTexture(0,0,1,1);
		if(t_path!=""){
			t_s.m_path=t_path;
		}
		return t_s;
	}
	internal static var m_list:Array;
	internal static var m_isLoading:Boolean;
	internal var m_loaded:int=0;
	public override function Width():int{
		return m_tex.m_orig_width;
	}
	internal var m_xstep:Number=.0;
	public override function Height():int{
		return m_tex.m_orig_height;
	}
	internal var m_ystep:Number=.0;
	public function p_LoadTexture(t_path:String,t_mesh:c_TMesh,t_device:c_MojoEmulationDevice):Boolean{
		m_tex.p_ResizeNoSmooth();
		m_tex.m_pixmap.p_ClearBind();
		c_TTexture.m_LoadAnimTexture(t_path,3,0,0,0,1,m_tex,1);
		m_loaded=1;
		m_xstep=1.0/(this.Width());
		m_ystep=1.0/(this.Height());
		return m_tex!=null;
	}
	public static function m_PreLoad(t_path:String,t_mesh:c_TMesh,t_device:c_MojoEmulationDevice):c_MojoSurface{
		var t_s:c_MojoSurface=m_Create(t_path);
		var t_sz:int=m_list.length;
		m_list=resize_string_array(m_list,t_sz+1);
		m_list[t_sz]=t_path;
		m_isLoading=true;
		t_s.p_LoadTexture(t_path,t_mesh,t_device);
		return t_s;
	}
	public override function Discard():int{
		if((m_tex)!=null){
			m_tex.p_FreeTexture();
		}
		m_tex=null;
		return 0;
	}
	public override function Loaded():int{
		return m_loaded;
	}
}
class c_List3 extends Object{
	public function m_List_new():c_List3{
		return this;
	}
	internal var m__head:c_Node4=((new c_HeadNode3).m_HeadNode_new());
	public function p_AddLast3(t_data:c_TMesh):c_Node4{
		return (new c_Node4).m_Node_new(m__head,m__head.m__pred,t_data);
	}
	public function m_List_new2(t_data:Array):c_List3{
		var t_:Array=t_data;
		var t_2:int=0;
		while(t_2<t_.length){
			var t_t:c_TMesh=t_[t_2];
			t_2=t_2+1;
			this.p_AddLast3(t_t);
		}
		return this;
	}
	public function p_Clear():int{
		m__head.m__succ=m__head;
		m__head.m__pred=m__head;
		return 0;
	}
	public function p_Compare2(t_lhs:c_TMesh,t_rhs:c_TMesh):int{
		error("Unable to compare items");
		return 0;
	}
	public function p_Sort(t_ascending:int):int{
		var t_ccsgn:int=-1;
		if((t_ascending)!=0){
			t_ccsgn=1;
		}
		var t_insize:int=1;
		do{
			var t_merges:int=0;
			var t_tail:c_Node4=m__head;
			var t_p:c_Node4=m__head.m__succ;
			while(t_p!=m__head){
				t_merges+=1;
				var t_q:c_Node4=t_p.m__succ;
				var t_qsize:int=t_insize;
				var t_psize:int=1;
				while(t_psize<t_insize && t_q!=m__head){
					t_psize+=1;
					t_q=t_q.m__succ;
				}
				do{
					var t_t:c_Node4=null;
					if(((t_psize)!=0) && ((t_qsize)!=0) && t_q!=m__head){
						var t_cc:int=this.p_Compare2(t_p.m__data,t_q.m__data)*t_ccsgn;
						if(t_cc<=0){
							t_t=t_p;
							t_p=t_p.m__succ;
							t_psize-=1;
						}else{
							t_t=t_q;
							t_q=t_q.m__succ;
							t_qsize-=1;
						}
					}else{
						if((t_psize)!=0){
							t_t=t_p;
							t_p=t_p.m__succ;
							t_psize-=1;
						}else{
							if(((t_qsize)!=0) && t_q!=m__head){
								t_t=t_q;
								t_q=t_q.m__succ;
								t_qsize-=1;
							}else{
								break;
							}
						}
					}
					t_t.m__pred=t_tail;
					t_tail.m__succ=t_t;
					t_tail=t_t;
				}while(!(false));
				t_p=t_q;
			}
			t_tail.m__succ=m__head;
			m__head.m__pred=t_tail;
			if(t_merges<=1){
				return 0;
			}
			t_insize*=2;
		}while(!(false));
		return 0;
	}
	public function p_ObjectEnumerator():c_Enumerator9{
		return (new c_Enumerator9).m_Enumerator_new(this);
	}
	public function p_IsEmpty():Boolean{
		return m__head.m__succ==m__head;
	}
}
class c_Node4 extends Object{
	internal var m__succ:c_Node4=null;
	internal var m__pred:c_Node4=null;
	internal var m__data:c_TMesh=null;
	public function m_Node_new(t_succ:c_Node4,t_pred:c_Node4,t_data:c_TMesh):c_Node4{
		m__succ=t_succ;
		m__pred=t_pred;
		m__succ.m__pred=this;
		m__pred.m__succ=this;
		m__data=t_data;
		return this;
	}
	public function m_Node_new2():c_Node4{
		return this;
	}
}
class c_HeadNode3 extends c_Node4{
	public function m_HeadNode_new():c_HeadNode3{
		super.m_Node_new2();
		m__succ=(this);
		m__pred=(this);
		return this;
	}
}
class c_TPixmap extends Object{
	internal static var m_preloader:c_TPixmapPreloader;
	public static function m_PreLoadPixmap(t_file:Array):int{
		return m_preloader.p_PreLoad2(t_file);
	}
	internal var m_bind:int=0;
	public function p_DecBind():void{
		m_bind-=1;
		if(m_bind<0){
			m_bind=0;
		}
	}
	public function p_GetBindCount():int{
		return m_bind;
	}
	public function p_FreePixmap():void{
		return;
	}
	internal static var m_manager:c_IPixmapManager;
	public static function m_LoadPixmap(t_f:String):c_TPixmap{
		return m_manager.p_LoadPixmap(t_f);
	}
	internal var m_width:int=0;
	internal var m_height:int=0;
	public function p_ResizePixmapNoSmooth(t_neww:int,t_newh:int):c_TPixmap{
		return null;
	}
	public function p_Copy():c_TPixmap{
		return this.p_ResizePixmapNoSmooth(m_width,m_height);
	}
	public function p_MaskPixmap(t_r:int,t_g:int,t_b:int):void{
	}
	public function p_ResizePixmap(t_neww:int,t_newh:int):c_TPixmap{
		return null;
	}
	public function p_SetPixel(t_x:int,t_y:int,t_r:int,t_g:int,t_b:int,t_a:int):void{
	}
	public static function m_CreatePixmap(t_w:int,t_h:int,t_format:int):c_TPixmap{
		return m_manager.p_CreatePixmap(t_w,t_h,t_format);
	}
	public function m_TPixmap_new():c_TPixmap{
		return this;
	}
	public function p_SetBind():void{
		m_bind+=1;
	}
	public function p_ClearBind():void{
		m_bind=0;
	}
}
class c_TPixmapPreloader extends Object{
	internal var m_manager:c_IPreloadManager=null;
	internal var m_old_file:Array=new_string_array(1);
	internal var m_start_stack:c_Stack2=(new c_Stack2).m_Stack_new();
	internal var m_finish_stack:c_Stack2=(new c_Stack2).m_Stack_new();
	internal var m_total:int=0;
	internal var m_loading:Boolean=false;
	public function p_CheckAllLoaded():int{
		if(m_start_stack.p_IsEmpty()){
			m_loading=false;
			return 1;
		}
		return 0;
	}
	public function p_PreLoad2(t_file:Array):int{
		if(!((m_manager)!=null)){
			error("**ERROR: no preload manager");
		}
		if(t_file[0]!=m_old_file[0] || t_file[t_file.length-1]!=m_old_file[m_old_file.length-1]){
			var t_:Array=t_file;
			var t_2:int=0;
			while(t_2<t_.length){
				var t_f:String=t_[t_2];
				t_2=t_2+1;
				if(t_f==""){
					continue;
				}
				var t_skip:Boolean=false;
				var t_3:c_Enumerator=m_start_stack.p_ObjectEnumerator();
				while(t_3.p_HasNext()){
					var t_ss:c_PixmapStack=t_3.p_NextObject();
					if(t_ss.m_file==t_f){
						t_skip=true;
						break;
					}
				}
				var t_4:c_Enumerator=m_finish_stack.p_ObjectEnumerator();
				while(t_4.p_HasNext()){
					var t_ss2:c_PixmapStack=t_4.p_NextObject();
					if(t_ss2.m_file==t_f){
						t_skip=true;
						break;
					}
				}
				if(t_skip!=true){
					m_total+=1;
					m_start_stack.p_Insert2(0,(new c_PixmapStack).m_PixmapStack_new(t_f,bb_data_FixDataPath(t_f),m_total));
				}
			}
			m_old_file=t_file;
		}
		if(!m_start_stack.p_IsEmpty()){
			m_loading=true;
			var t_f2:c_PixmapStack=null;
			var t_5:c_BackwardsEnumerator=m_start_stack.p_Backwards().p_ObjectEnumerator();
			while(t_5.p_HasNext()){
				t_f2=t_5.p_NextObject();
				if(t_f2.m_loading==false){
					m_manager.p_PreLoadData(t_f2.m_file,t_f2.m_id);
					t_f2.m_loading=true;
					break;
				}else{
					if(m_manager.p_IsLoaded(t_f2.m_id)){
						m_start_stack.p_RemoveEach(t_f2);
						m_finish_stack.p_Push4(t_f2);
					}
				}
			}
		}
		return this.p_CheckAllLoaded();
	}
	public function p_RemoveFromStack(t_file:String):void{
		if(!m_finish_stack.p_IsEmpty()){
			var t_j:int=0;
			var t_:c_Enumerator=m_finish_stack.p_ObjectEnumerator();
			while(t_.p_HasNext()){
				var t_i:c_PixmapStack=t_.p_NextObject();
				t_j=t_j+1;
				if(t_i.m_file==t_file || t_i.m_new_file==t_file){
					m_finish_stack.p_Remove2(t_j);
					break;
				}
			}
		}
	}
	public function m_TPixmapPreloader_new(t_m:c_IPreloadManager):c_TPixmapPreloader{
		m_manager=t_m;
		return this;
	}
	public function m_TPixmapPreloader_new2():c_TPixmapPreloader{
		return this;
	}
	public function p_GetID(t_file:String):int{
		if(!m_finish_stack.p_IsEmpty()){
			var t_:c_Enumerator=m_finish_stack.p_ObjectEnumerator();
			while(t_.p_HasNext()){
				var t_i:c_PixmapStack=t_.p_NextObject();
				if(t_i.m_file==t_file || t_i.m_new_file==t_file){
					return t_i.m_id;
				}
			}
		}
		return 0;
	}
	public function p_GetPixmapPreLoad(t_p:c_TPixmap,t_file:String):void{
		var t_id:int=this.p_GetID(t_file);
		m_manager.p_SetPixmapFromID(t_p,t_id,t_file);
	}
}
interface c_IPreloadManager{
	function p_PreLoadData(t_f:String,t_file_id:int):void;
	function p_IsLoaded(t_file_id:int):Boolean;
	function p_SetPixmapFromID(t_pixmap:c_TPixmap,t_file_id:int,t_file:String):void;
}
class c_PixmapStack extends Object{
	internal var m_file:String="";
	internal var m_new_file:String="";
	internal var m_id:int=0;
	public function m_PixmapStack_new(t_f:String,t_nf:String,t_i:int):c_PixmapStack{
		m_file=t_f;
		m_new_file=t_nf;
		m_id=t_i;
		return this;
	}
	public function m_PixmapStack_new2():c_PixmapStack{
		return this;
	}
	internal var m_loading:Boolean=false;
}
class c_Stack2 extends Object{
	public function m_Stack_new():c_Stack2{
		return this;
	}
	internal var m_data:Array=[];
	internal var m_length:int=0;
	public function m_Stack_new2(t_data:Array):c_Stack2{
		this.m_data=t_data.slice(0);
		this.m_length=t_data.length;
		return this;
	}
	public function p_ObjectEnumerator():c_Enumerator{
		return (new c_Enumerator).m_Enumerator_new(this);
	}
	internal static var m_NIL:c_PixmapStack;
	public function p_Length(t_newlength:int):void{
		if(t_newlength<m_length){
			for(var t_i:int=t_newlength;t_i<m_length;t_i=t_i+1){
				m_data[t_i]=m_NIL;
			}
		}else{
			if(t_newlength>m_data.length){
				m_data=resize_object_array(m_data,bb_math2_Max(m_length*2+10,t_newlength));
			}
		}
		m_length=t_newlength;
	}
	public function p_Length2():int{
		return m_length;
	}
	public function p_Insert2(t_index:int,t_value:c_PixmapStack):void{
		if(m_length==m_data.length){
			m_data=resize_object_array(m_data,m_length*2+10);
		}
		for(var t_i:int=m_length;t_i>t_index;t_i=t_i+-1){
			m_data[t_i]=m_data[t_i-1];
		}
		m_data[t_index]=t_value;
		m_length+=1;
	}
	public function p_IsEmpty():Boolean{
		return m_length==0;
	}
	public function p_Backwards():c_BackwardsStack{
		return (new c_BackwardsStack).m_BackwardsStack_new(this);
	}
	public function p_Equals(t_lhs:c_PixmapStack,t_rhs:c_PixmapStack):Boolean{
		return t_lhs==t_rhs;
	}
	public function p_RemoveEach(t_value:c_PixmapStack):void{
		var t_i:int=0;
		var t_j:int=m_length;
		while(t_i<m_length){
			if(!this.p_Equals(m_data[t_i],t_value)){
				t_i+=1;
				continue;
			}
			var t_b:int=t_i;
			var t_e:int=t_i+1;
			while(t_e<m_length && this.p_Equals(m_data[t_e],t_value)){
				t_e+=1;
			}
			while(t_e<m_length){
				m_data[t_b]=m_data[t_e];
				t_b+=1;
				t_e+=1;
			}
			m_length-=t_e-t_b;
			t_i+=1;
		}
		t_i=m_length;
		while(t_i<t_j){
			m_data[t_i]=m_NIL;
			t_i+=1;
		}
	}
	public function p_Push4(t_value:c_PixmapStack):void{
		if(m_length==m_data.length){
			m_data=resize_object_array(m_data,m_length*2+10);
		}
		m_data[m_length]=t_value;
		m_length+=1;
	}
	public function p_Push5(t_values:Array,t_offset:int,t_count:int):void{
		for(var t_i:int=0;t_i<t_count;t_i=t_i+1){
			this.p_Push4(t_values[t_offset+t_i]);
		}
	}
	public function p_Push6(t_values:Array,t_offset:int):void{
		this.p_Push5(t_values,t_offset,t_values.length-t_offset);
	}
	public function p_Remove2(t_index:int):void{
		for(var t_i:int=t_index;t_i<m_length-1;t_i=t_i+1){
			m_data[t_i]=m_data[t_i+1];
		}
		m_length-=1;
		m_data[m_length]=m_NIL;
	}
}
class c_Enumerator extends Object{
	internal var m_stack:c_Stack2=null;
	public function m_Enumerator_new(t_stack:c_Stack2):c_Enumerator{
		this.m_stack=t_stack;
		return this;
	}
	public function m_Enumerator_new2():c_Enumerator{
		return this;
	}
	internal var m_index:int=0;
	public function p_HasNext():Boolean{
		return m_index<m_stack.p_Length2();
	}
	public function p_NextObject():c_PixmapStack{
		m_index+=1;
		return m_stack.m_data[m_index-1];
	}
}
internal function bb_math2_Max(t_x:int,t_y:int):int{
	if(t_x>t_y){
		return t_x;
	}
	return t_y;
}
internal function bb_math2_Max2(t_x:Number,t_y:Number):Number{
	if(t_x>t_y){
		return t_x;
	}
	return t_y;
}
class c_BackwardsStack extends Object{
	internal var m_stack:c_Stack2=null;
	public function m_BackwardsStack_new(t_stack:c_Stack2):c_BackwardsStack{
		this.m_stack=t_stack;
		return this;
	}
	public function m_BackwardsStack_new2():c_BackwardsStack{
		return this;
	}
	public function p_ObjectEnumerator():c_BackwardsEnumerator{
		return (new c_BackwardsEnumerator).m_BackwardsEnumerator_new(m_stack);
	}
}
class c_BackwardsEnumerator extends Object{
	internal var m_stack:c_Stack2=null;
	internal var m_index:int=0;
	public function m_BackwardsEnumerator_new(t_stack:c_Stack2):c_BackwardsEnumerator{
		this.m_stack=t_stack;
		m_index=t_stack.m_length;
		return this;
	}
	public function m_BackwardsEnumerator_new2():c_BackwardsEnumerator{
		return this;
	}
	public function p_HasNext():Boolean{
		return m_index>0;
	}
	public function p_NextObject():c_PixmapStack{
		m_index-=1;
		return m_stack.m_data[m_index];
	}
}
internal function bb_functions_PreLoadPixmap(t_fs:Array):int{
	return c_TPixmap.m_PreLoadPixmap(t_fs);
}
internal function bb_functions_PreLoadPixmap2(t_fs:String):int{
	return c_TPixmap.m_PreLoadPixmap([t_fs]);
}
internal function bb_mojographics_SetMojoEmulation():void{
	c_MojoEmulationDevice.m_SetDevice();
}
internal function bb_flash11_SetRender(t_flags:int):int{
	c_TRender.m_render=((new c_FlashMiniB3D).m_FlashMiniB3D_new());
	c_TRender.m_render.p_GraphicsInit(t_flags);
	bb_mojographics_SetMojoEmulation();
	return 0;
}
class c_List4 extends Object{
	public function m_List_new():c_List4{
		return this;
	}
	internal var m__head:c_Node5=((new c_HeadNode4).m_HeadNode_new());
	public function p_AddLast4(t_data:String):c_Node5{
		return (new c_Node5).m_Node_new(m__head,m__head.m__pred,t_data);
	}
	public function m_List_new2(t_data:Array):c_List4{
		var t_:Array=t_data;
		var t_2:int=0;
		while(t_2<t_.length){
			var t_t:String=t_[t_2];
			t_2=t_2+1;
			this.p_AddLast4(t_t);
		}
		return this;
	}
	public function p_Count():int{
		var t_n:int=0;
		var t_node:c_Node5=m__head.m__succ;
		while(t_node!=m__head){
			t_node=t_node.m__succ;
			t_n+=1;
		}
		return t_n;
	}
	public function p_ObjectEnumerator():c_Enumerator2{
		return (new c_Enumerator2).m_Enumerator_new(this);
	}
	public function p_ToArray():Array{
		var t_arr:Array=new_string_array(this.p_Count());
		var t_i:int=0;
		var t_:c_Enumerator2=this.p_ObjectEnumerator();
		while(t_.p_HasNext()){
			var t_t:String=t_.p_NextObject();
			t_arr[t_i]=t_t;
			t_i+=1;
		}
		return t_arr;
	}
}
class c_StringList extends c_List4{
	public function m_StringList_new(t_data:Array):c_StringList{
		super.m_List_new2(t_data);
		return this;
	}
	public function m_StringList_new2():c_StringList{
		super.m_List_new();
		return this;
	}
}
class c_Node5 extends Object{
	internal var m__succ:c_Node5=null;
	internal var m__pred:c_Node5=null;
	internal var m__data:String="";
	public function m_Node_new(t_succ:c_Node5,t_pred:c_Node5,t_data:String):c_Node5{
		m__succ=t_succ;
		m__pred=t_pred;
		m__succ.m__pred=this;
		m__pred.m__succ=this;
		m__data=t_data;
		return this;
	}
	public function m_Node_new2():c_Node5{
		return this;
	}
}
class c_HeadNode4 extends c_Node5{
	public function m_HeadNode_new():c_HeadNode4{
		super.m_Node_new2();
		m__succ=(this);
		m__pred=(this);
		return this;
	}
}
class c_Enumerator2 extends Object{
	internal var m__list:c_List4=null;
	internal var m__curr:c_Node5=null;
	public function m_Enumerator_new(t_list:c_List4):c_Enumerator2{
		m__list=t_list;
		m__curr=t_list.m__head.m__succ;
		return this;
	}
	public function m_Enumerator_new2():c_Enumerator2{
		return this;
	}
	public function p_HasNext():Boolean{
		while(m__curr.m__succ.m__pred!=m__curr){
			m__curr=m__curr.m__succ;
		}
		return m__curr!=m__list.m__head;
	}
	public function p_NextObject():String{
		var t_data:String=m__curr.m__data;
		m__curr=m__curr.m__succ;
		return t_data;
	}
}
internal function bb_app2_Millisecs():int{
	return bb_app2__game.Millisecs();
}
class c_Stack3 extends Object{
	public function m_Stack_new():c_Stack3{
		return this;
	}
	internal var m_data:Array=[];
	internal var m_length:int=0;
	public function m_Stack_new2(t_data:Array):c_Stack3{
		this.m_data=t_data.slice(0);
		this.m_length=t_data.length;
		return this;
	}
	internal static var m_NIL:c_TTexture;
	public function p_Length(t_newlength:int):void{
		if(t_newlength<m_length){
			for(var t_i:int=t_newlength;t_i<m_length;t_i=t_i+1){
				m_data[t_i]=m_NIL;
			}
		}else{
			if(t_newlength>m_data.length){
				m_data=resize_object_array(m_data,bb_math2_Max(m_length*2+10,t_newlength));
			}
		}
		m_length=t_newlength;
	}
	public function p_Length2():int{
		return m_length;
	}
	public function p_ObjectEnumerator():c_Enumerator3{
		return (new c_Enumerator3).m_Enumerator_new(this);
	}
	public function p_Clear():void{
		for(var t_i:int=0;t_i<m_length;t_i=t_i+1){
			m_data[t_i]=m_NIL;
		}
		m_length=0;
	}
	public function p_Push7(t_value:c_TTexture):void{
		if(m_length==m_data.length){
			m_data=resize_object_array(m_data,m_length*2+10);
		}
		m_data[m_length]=t_value;
		m_length+=1;
	}
	public function p_Push8(t_values:Array,t_offset:int,t_count:int):void{
		for(var t_i:int=0;t_i<t_count;t_i=t_i+1){
			this.p_Push7(t_values[t_offset+t_i]);
		}
	}
	public function p_Push9(t_values:Array,t_offset:int):void{
		this.p_Push8(t_values,t_offset,t_values.length-t_offset);
	}
}
class c_TextureStack extends c_Stack3{
	public function m_TextureStack_new():c_TextureStack{
		super.m_Stack_new();
		return this;
	}
}
class c_Enumerator3 extends Object{
	internal var m_stack:c_Stack3=null;
	public function m_Enumerator_new(t_stack:c_Stack3):c_Enumerator3{
		this.m_stack=t_stack;
		return this;
	}
	public function m_Enumerator_new2():c_Enumerator3{
		return this;
	}
	internal var m_index:int=0;
	public function p_HasNext():Boolean{
		return m_index<m_stack.p_Length2();
	}
	public function p_NextObject():c_TTexture{
		m_index+=1;
		return m_stack.m_data[m_index-1];
	}
}
class c_Node6 extends Object{
	internal var m__pred:c_Node6=null;
	internal var m__succ:c_Node6=null;
	public function p_Remove():int{
		m__succ.m__pred=m__pred;
		m__pred.m__succ=m__succ;
		return 0;
	}
	internal var m__data:c_TTexture=null;
	public function m_Node_new(t_succ:c_Node6,t_pred:c_Node6,t_data:c_TTexture):c_Node6{
		m__succ=t_succ;
		m__pred=t_pred;
		m__succ.m__pred=this;
		m__pred.m__succ=this;
		m__data=t_data;
		return this;
	}
	public function m_Node_new2():c_Node6{
		return this;
	}
}
class c_TCamera extends c_TEntity{
	internal static var m_cam_list:c_EntityList2;
	internal var m_fov_y:Number=.0;
	internal var m_range_near:Number=1.0;
	internal var m_range_far:Number=1000.0;
	internal var m_aspect:Number=.0;
	internal var m_viewport:Array=new_number_array(4);
	internal var m_eyedx:Number=0.0;
	internal var m_focus:Number=1.0;
	internal var m_eyedy:Number=0.0;
	internal var m_proj_mode:int=1;
	internal var m_proj_mat:c_Matrix=(new c_Matrix).m_Matrix_new();
	internal var m_draw2D:int=0;
	internal var m_oldw:int=0;
	internal var m_vwidth:int=0;
	internal var m_oldh:int=0;
	internal var m_vheight:int=0;
	internal var m_vx:int=0;
	internal var m_vy:int=0;
	internal var m_mod_mat:c_Matrix=(new c_Matrix).m_Matrix_new();
	internal var m_view_mat:c_Matrix=(new c_Matrix).m_Matrix_new();
	internal var m_projview_mat:c_Matrix=(new c_Matrix).m_Matrix_new();
	public function p_SetPixelCamera():int{
		if(((m_draw2D)!=0) && m_oldw==m_vwidth && m_oldh==m_vheight){
			return 0;
		}
		m_oldw=m_vwidth;
		m_oldh=m_vheight;
		m_draw2D=1;
		if(m_name==""){
			m_name="pixel";
		}
		var t_left:Number=(m_vx)-(m_vwidth)*0.5;
		var t_right:Number=(m_vwidth)+t_left;
		var t_bottom:Number=(m_vy)-(m_vheight)/2.0;
		var t_top:Number=(m_vheight)+t_bottom;
		var t_near:Number=1.0;
		var t_far:Number=2.0;
		var t_tx:Number=-(t_right+t_left)/(t_right-t_left);
		var t_ty:Number=-(t_top+t_bottom)/(t_top-t_bottom);
		var t_tz:Number=-(t_far+t_near)/(t_far-t_near);
		m_proj_mat.m_grid[0][0]=2.0/(t_right-t_left);
		m_proj_mat.m_grid[0][1]=0.0;
		m_proj_mat.m_grid[0][2]=0.0;
		m_proj_mat.m_grid[0][3]=0.0;
		m_proj_mat.m_grid[1][0]=0.0;
		m_proj_mat.m_grid[1][1]=2.0/(t_top-t_bottom);
		m_proj_mat.m_grid[1][2]=0.0;
		m_proj_mat.m_grid[1][3]=0.0;
		m_proj_mat.m_grid[2][0]=0.0;
		m_proj_mat.m_grid[2][1]=0.0;
		m_proj_mat.m_grid[2][2]=-2.0/(t_far-t_near);
		m_proj_mat.m_grid[2][3]=0.0;
		m_proj_mat.m_grid[3][0]=t_tx-1.0;
		m_proj_mat.m_grid[3][1]=t_ty+1.0;
		m_proj_mat.m_grid[3][2]=t_tz;
		m_proj_mat.m_grid[3][3]=1.0;
		m_mod_mat.p_LoadIdentity();
		m_mat.p_LoadIdentity();
		m_view_mat=m_mod_mat;
		m_projview_mat.p_Overwrite(m_proj_mat);
		return 0;
	}
	public function p_accFrustum(t_left_:Number,t_right_:Number,t_bottom:Number,t_top:Number,t_zNear:Number,t_zFar:Number,t_pixdx:Number,t_pixdy:Number):int{
		var t_xwsize:Number=.0;
		var t_ywsize:Number=.0;
		var t_dx:Number=.0;
		var t_dy:Number=.0;
		if(((t_pixdx)!=0.0) || ((t_pixdy)!=0.0)){
			t_xwsize=t_right_-t_left_;
			t_ywsize=t_top-t_bottom;
			t_dx=-(t_pixdx*t_xwsize/(m_viewport[2])+m_eyedx*t_zNear/m_focus);
			t_dy=-(t_pixdy*t_ywsize/(m_viewport[3])+m_eyedy*t_zNear/m_focus);
		}
		if(m_proj_mode==1){
			if(m_name==""){
				m_name="perspective";
			}
			t_left_+=t_dx;
			t_right_+=t_dx;
			t_bottom+=t_dy;
			t_top+=t_dy;
			m_proj_mat.m_grid[0][0]=2.0*t_zNear/(t_right_-t_left_);
			m_proj_mat.m_grid[1][0]=0.0;
			m_proj_mat.m_grid[2][0]=(t_right_+t_left_)/(t_right_-t_left_);
			m_proj_mat.m_grid[3][0]=0.0;
			m_proj_mat.m_grid[0][1]=0.0;
			m_proj_mat.m_grid[1][1]=2.0*t_zNear/(t_top-t_bottom);
			m_proj_mat.m_grid[2][1]=(t_top+t_bottom)/(t_top-t_bottom);
			m_proj_mat.m_grid[3][1]=0.0;
			m_proj_mat.m_grid[0][2]=0.0;
			m_proj_mat.m_grid[1][2]=0.0;
			m_proj_mat.m_grid[2][2]=-(t_zFar+t_zNear)/(t_zFar-t_zNear);
			m_proj_mat.m_grid[3][2]=-(2.0*t_zFar*t_zNear)/(t_zFar-t_zNear);
			m_proj_mat.m_grid[0][3]=0.0;
			m_proj_mat.m_grid[1][3]=0.0;
			m_proj_mat.m_grid[2][3]=-1.0;
			m_proj_mat.m_grid[3][3]=0.0;
		}else{
			if(m_proj_mode==2){
				if(m_name==""){
					m_name="isometric";
				}
				t_left_+=t_dx;
				t_right_+=t_dx;
				t_bottom+=t_dy;
				t_top+=t_dy;
				m_proj_mat.m_grid[0][0]=2.0/(t_right_-t_left_);
				m_proj_mat.m_grid[0][1]=0.0;
				m_proj_mat.m_grid[0][2]=0.0;
				m_proj_mat.m_grid[0][3]=0.0;
				m_proj_mat.m_grid[1][0]=0.0;
				m_proj_mat.m_grid[1][1]=2.0/(t_top-t_bottom);
				m_proj_mat.m_grid[1][2]=0.0;
				m_proj_mat.m_grid[1][3]=0.0;
				m_proj_mat.m_grid[2][0]=0.0;
				m_proj_mat.m_grid[2][1]=0.0;
				m_proj_mat.m_grid[2][2]=-2.0/(t_zFar-t_zNear);
				m_proj_mat.m_grid[2][3]=0.0;
				m_proj_mat.m_grid[3][0]=-(t_right_+t_left_)/(t_right_-t_left_);
				m_proj_mat.m_grid[3][1]=-(t_top+t_bottom)/(t_top-t_bottom);
				m_proj_mat.m_grid[3][2]=-(t_zFar+t_zNear)/(t_zFar-t_zNear);
				m_proj_mat.m_grid[3][3]=1.0;
			}else{
				if(m_proj_mode==3){
					this.p_SetPixelCamera();
				}
			}
		}
		return 0;
	}
	public function p_accPerspective(t_fovy:Number,t_zNear:Number,t_zFar:Number,t_pixdx:Number,t_pixdy:Number):int{
		var t_fov2:Number=.0;
		var t_left_:Number=.0;
		var t_right_:Number=.0;
		var t_bottom:Number=.0;
		var t_top:Number=.0;
		t_fov2=t_fovy*0.5;
		t_top=t_zNear/(Math.cos((t_fov2)*D2R)/Math.sin((t_fov2)*D2R));
		t_bottom=-t_top;
		t_right_=t_top*m_aspect;
		t_left_=-t_right_;
		this.p_accFrustum(t_left_,t_right_,t_bottom,t_top,t_zNear,t_zFar,t_pixdx,t_pixdy);
		return 0;
	}
	internal var m_frustum:Array=[];
	public function p_ExtractFrustum():int{
		var t_clip:Array=m_projview_mat.p_ToArray();
		var t_t:Number=.0;
		m_frustum[0][0]=t_clip[3]-t_clip[0];
		m_frustum[0][1]=t_clip[7]-t_clip[4];
		m_frustum[0][2]=t_clip[11]-t_clip[8];
		m_frustum[0][3]=t_clip[15]-t_clip[12];
		t_t=1.0/Math.sqrt(m_frustum[0][0]*m_frustum[0][0]+m_frustum[0][1]*m_frustum[0][1]+m_frustum[0][2]*m_frustum[0][2]);
		m_frustum[0][0]*=t_t;
		m_frustum[0][1]*=t_t;
		m_frustum[0][2]*=t_t;
		m_frustum[0][3]*=t_t;
		m_frustum[1][0]=t_clip[3]+t_clip[0];
		m_frustum[1][1]=t_clip[7]+t_clip[4];
		m_frustum[1][2]=t_clip[11]+t_clip[8];
		m_frustum[1][3]=t_clip[15]+t_clip[12];
		t_t=1.0/Math.sqrt(m_frustum[1][0]*m_frustum[1][0]+m_frustum[1][1]*m_frustum[1][1]+m_frustum[1][2]*m_frustum[1][2]);
		m_frustum[1][0]*=t_t;
		m_frustum[1][1]*=t_t;
		m_frustum[1][2]*=t_t;
		m_frustum[1][3]*=t_t;
		m_frustum[2][0]=t_clip[3]+t_clip[1];
		m_frustum[2][1]=t_clip[7]+t_clip[5];
		m_frustum[2][2]=t_clip[11]+t_clip[9];
		m_frustum[2][3]=t_clip[15]+t_clip[13];
		t_t=1.0/Math.sqrt(m_frustum[2][0]*m_frustum[2][0]+m_frustum[2][1]*m_frustum[2][1]+m_frustum[2][2]*m_frustum[2][2]);
		m_frustum[2][0]*=t_t;
		m_frustum[2][1]*=t_t;
		m_frustum[2][2]*=t_t;
		m_frustum[2][3]*=t_t;
		m_frustum[3][0]=t_clip[3]-t_clip[1];
		m_frustum[3][1]=t_clip[7]-t_clip[5];
		m_frustum[3][2]=t_clip[11]-t_clip[9];
		m_frustum[3][3]=t_clip[15]-t_clip[13];
		t_t=1.0/Math.sqrt(m_frustum[3][0]*m_frustum[3][0]+m_frustum[3][1]*m_frustum[3][1]+m_frustum[3][2]*m_frustum[3][2]);
		m_frustum[3][0]*=t_t;
		m_frustum[3][1]*=t_t;
		m_frustum[3][2]*=t_t;
		m_frustum[3][3]*=t_t;
		m_frustum[4][0]=t_clip[3]-t_clip[2];
		m_frustum[4][1]=t_clip[7]-t_clip[6];
		m_frustum[4][2]=t_clip[11]-t_clip[10];
		m_frustum[4][3]=t_clip[15]-t_clip[14];
		t_t=1.0/Math.sqrt(m_frustum[4][0]*m_frustum[4][0]+m_frustum[4][1]*m_frustum[4][1]+m_frustum[4][2]*m_frustum[4][2]);
		m_frustum[4][0]*=t_t;
		m_frustum[4][1]*=t_t;
		m_frustum[4][2]*=t_t;
		m_frustum[4][3]*=t_t;
		m_frustum[5][0]=t_clip[3]+t_clip[2];
		m_frustum[5][1]=t_clip[7]+t_clip[6];
		m_frustum[5][2]=t_clip[11]+t_clip[10];
		m_frustum[5][3]=t_clip[15]+t_clip[14];
		t_t=1.0/Math.sqrt(m_frustum[5][0]*m_frustum[5][0]+m_frustum[5][1]*m_frustum[5][1]+m_frustum[5][2]*m_frustum[5][2]);
		m_frustum[5][0]*=t_t;
		m_frustum[5][1]*=t_t;
		m_frustum[5][2]*=t_t;
		m_frustum[5][3]*=t_t;
		return 0;
	}
	public function p_Update2(t_cam:c_TCamera):int{
		this.p_accPerspective(m_fov_y,m_range_near,m_range_far,0.0,0.0);
		m_mod_mat=m_mat.p_Inverse();
		if(((m_eyedx)!=0.0) || ((m_eyedy)!=0.0)){
			m_mod_mat.p_Translate(-m_eyedx,-m_eyedy,0.0);
		}
		m_view_mat=m_mod_mat;
		m_projview_mat.p_Overwrite(m_proj_mat);
		m_projview_mat.p_Multiply4(m_mod_mat);
		if((t_cam)!=null){
			this.p_ExtractFrustum();
		}
		return 0;
	}
	public function p_EntityInFrustum(t_ent:c_TEntity):Number{
		var t_x:Number=t_ent.p_EntityX(1);
		var t_y:Number=t_ent.p_EntityY(1);
		var t_z:Number=t_ent.p_EntityZ(1);
		var t_radius:Number=bb_math2_Abs2(t_ent.m_cull_radius);
		var t_mesh:c_TMesh=((t_ent) as c_TMesh);
		if((t_mesh)!=null){
			var t_r:Array=t_ent.m_mat.p_TransformPoint(t_mesh.m_center_x,t_mesh.m_center_y,t_mesh.m_center_z,1.0);
			t_x=t_r[0];
			t_y=t_r[1];
			t_z=t_r[2];
			var t_gs:Number=bb_math2_Max2(bb_math2_Max2(t_ent.m_gsx,t_ent.m_gsy),t_ent.m_gsz);
			t_radius=t_radius*t_gs;
			if(t_radius<0.0){
				t_radius=-t_radius;
			}
		}
		var t_d:Number=.0;
		t_d=m_frustum[0][0]*t_x+m_frustum[0][1]*t_y+m_frustum[0][2]*t_z+m_frustum[0][3];
		if(t_d<=-t_radius){
			return 0.0;
		}
		t_d=m_frustum[1][0]*t_x+m_frustum[1][1]*t_y+m_frustum[1][2]*t_z+m_frustum[1][3];
		if(t_d<=-t_radius){
			return 0.0;
		}
		t_d=m_frustum[2][0]*t_x+m_frustum[2][1]*t_y+m_frustum[2][2]*t_z+m_frustum[2][3];
		if(t_d<=-t_radius){
			return 0.0;
		}
		t_d=m_frustum[3][0]*t_x+m_frustum[3][1]*t_y+m_frustum[3][2]*t_z+m_frustum[3][3];
		if(t_d<=-t_radius){
			return 0.0;
		}
		t_d=m_frustum[4][0]*t_x+m_frustum[4][1]*t_y+m_frustum[4][2]*t_z+m_frustum[4][3];
		if(t_d<=-t_radius){
			return 0.0;
		}
		t_d=m_frustum[5][0]*t_x+m_frustum[5][1]*t_y+m_frustum[5][2]*t_z+m_frustum[5][3];
		if(t_d<=-t_radius){
			return 0.0;
		}
		return t_d+t_radius;
	}
	public function m_TCamera_new():c_TCamera{
		super.m_TEntity_new();
		m_frustum=bb_monkeyutility_AllocateFloatArray(6,4);
		return this;
	}
	internal var m_cls_color:Boolean=true;
	internal var m_cls_zbuffer:Boolean=true;
	public function p_CameraClsMode(t_color:Boolean,t_zbuffer:Boolean):int{
		m_cls_color=t_color;
		m_cls_zbuffer=t_zbuffer;
		return 0;
	}
	internal var m_zoom:Number=1.0;
	internal var m_inv_zoom:Number=1.0;
	public function p_CameraZoom(t_zoom_val:Number):int{
		m_zoom=t_zoom_val;
		m_inv_zoom=1.0/t_zoom_val;
		m_fov_y=(Math.atan(1.0/(m_zoom*((m_vwidth)/(m_vheight))))*R2D)*2.0;
		return 0;
	}
	public function p_CameraViewport(t_x:int,t_y:int,t_w:int,t_h:int):int{
		m_vx=t_x;
		m_vy=c_TRender.m_height-t_h-t_y;
		m_vwidth=t_w;
		m_vheight=t_h;
		this.p_CameraZoom(m_zoom);
		m_aspect=(m_vwidth)/(m_vheight);
		m_viewport[0]=m_vx;
		m_viewport[1]=m_vy;
		m_viewport[2]=t_w;
		m_viewport[3]=t_h;
		return 0;
	}
	internal var m_cam_link:c_Node7=null;
	public static function m_CreateCamera(t_parent_ent:c_TEntity):c_TCamera{
		var t_cam:c_TCamera=(new c_TCamera).m_TCamera_new();
		t_cam.p_CameraViewport(0,0,c_TRender.m_width,c_TRender.m_height);
		t_cam.m_classname="Camera";
		t_cam.m_name="proj"+String(m_cam_list.p_Count());
		t_cam.p_AddParent(t_parent_ent);
		t_cam.m_entity_link=c_TEntity.m_entity_list.p_EntityListAdd(t_cam);
		t_cam.m_cam_link=m_cam_list.p_EntityListAdd2(t_cam);
		if(t_cam.m_parent!=null){
			t_cam.m_mat.p_Overwrite(t_cam.m_parent.m_mat);
			t_cam.p_UpdateMat(false);
		}else{
			t_cam.p_UpdateMat(true);
		}
		return t_cam;
	}
	internal var m_cls_r:Number=0.0;
	internal var m_cls_g:Number=0.0;
	internal var m_cls_b:Number=0.0;
	public function p_CameraClsColor(t_r:Number,t_g:Number,t_b:Number):int{
		m_cls_r=t_r/255.0;
		m_cls_g=t_g/255.0;
		m_cls_b=t_b/255.0;
		return 0;
	}
	internal var m_fog_mode:int=0;
	public function p_CameraScissor(t_x:int,t_y:int,t_w:int,t_h:int):int{
		if(t_x<0){
			t_x=0;
		}
		if(t_x>c_TRender.m_width){
			t_x=c_TRender.m_width;
		}
		if(t_y<0){
			t_y=0;
		}
		if(t_y>c_TRender.m_height){
			t_y=c_TRender.m_height;
		}
		if(t_w<0){
			t_w=0;
		}
		if(t_w>c_TRender.m_width){
			t_w=c_TRender.m_width;
		}
		if(t_h<0){
			t_h=0;
		}
		if(t_h>c_TRender.m_height){
			t_h=c_TRender.m_height;
		}
		t_y=c_TRender.m_height-t_h-t_y;
		m_viewport[0]=t_x;
		m_viewport[1]=t_y;
		m_viewport[2]=t_w;
		m_viewport[3]=t_h;
		return 0;
	}
}
class c_List5 extends Object{
	public function m_List_new():c_List5{
		return this;
	}
	internal var m__head:c_Node7=((new c_HeadNode5).m_HeadNode_new());
	public function p_AddLast5(t_data:c_TCamera):c_Node7{
		return (new c_Node7).m_Node_new(m__head,m__head.m__pred,t_data);
	}
	public function m_List_new2(t_data:Array):c_List5{
		var t_:Array=t_data;
		var t_2:int=0;
		while(t_2<t_.length){
			var t_t:c_TCamera=t_[t_2];
			t_2=t_2+1;
			this.p_AddLast5(t_t);
		}
		return this;
	}
	public function p_ObjectEnumerator():c_Enumerator4{
		return (new c_Enumerator4).m_Enumerator_new(this);
	}
	public function p_Count():int{
		var t_n:int=0;
		var t_node:c_Node7=m__head.m__succ;
		while(t_node!=m__head){
			t_node=t_node.m__succ;
			t_n+=1;
		}
		return t_n;
	}
	public function p_FirstNode():c_Node7{
		if(m__head.m__succ!=m__head){
			return m__head.m__succ;
		}
		return null;
	}
	public function p_AddFirst2(t_data:c_TCamera):c_Node7{
		return (new c_Node7).m_Node_new(m__head.m__succ,m__head,t_data);
	}
}
class c_EntityList2 extends c_List5{
	public function m_EntityList_new():c_EntityList2{
		super.m_List_new();
		return this;
	}
	public function p_EntityListAdd2(t_obj:c_TCamera):c_Node7{
		var t_llink:c_Node7=this.p_FirstNode();
		if(t_obj.m_order>0){
			t_llink=this.p_AddFirst2(t_obj);
			return t_llink;
		}else{
			t_llink=this.p_AddLast5(t_obj);
			return t_llink;
		}
		return null;
	}
}
class c_Node7 extends Object{
	internal var m__succ:c_Node7=null;
	internal var m__pred:c_Node7=null;
	internal var m__data:c_TCamera=null;
	public function m_Node_new(t_succ:c_Node7,t_pred:c_Node7,t_data:c_TCamera):c_Node7{
		m__succ=t_succ;
		m__pred=t_pred;
		m__succ.m__pred=this;
		m__pred.m__succ=this;
		m__data=t_data;
		return this;
	}
	public function m_Node_new2():c_Node7{
		return this;
	}
}
class c_HeadNode5 extends c_Node7{
	public function m_HeadNode_new():c_HeadNode5{
		super.m_Node_new2();
		m__succ=(this);
		m__pred=(this);
		return this;
	}
}
class c_Enumerator4 extends Object{
	internal var m__list:c_List5=null;
	internal var m__curr:c_Node7=null;
	public function m_Enumerator_new(t_list:c_List5):c_Enumerator4{
		m__list=t_list;
		m__curr=t_list.m__head.m__succ;
		return this;
	}
	public function m_Enumerator_new2():c_Enumerator4{
		return this;
	}
	public function p_HasNext():Boolean{
		while(m__curr.m__succ.m__pred!=m__curr){
			m__curr=m__curr.m__succ;
		}
		return m__curr!=m__list.m__head;
	}
	public function p_NextObject():c_TCamera{
		var t_data:c_TCamera=m__curr.m__data;
		m__curr=m__curr.m__succ;
		return t_data;
	}
}
class c_TShader extends c_TBrush{
	internal static var m_process_list:c_List6;
	public static function m_PreProcess(t_cam:c_TCamera):int{
		var t_:c_Enumerator5=m_process_list.p_ObjectEnumerator();
		while(t_.p_HasNext()){
			var t_sh:c_TShader=t_.p_NextObject();
			((t_sh) as c_IShaderProcess).p_PreProcess(t_cam);
		}
		return 0;
	}
	internal static var m_g_shader:c_TShader;
	public static function m_PostProcess(t_cam:c_TCamera):int{
		var t_:c_Enumerator5=m_process_list.p_ObjectEnumerator();
		while(t_.p_HasNext()){
			var t_sh:c_TShader=t_.p_NextObject();
			((t_sh) as c_IShaderProcess).p_PostProcess(t_cam);
		}
		return 0;
	}
	public function m_TShader_new():c_TShader{
		super.m_TBrush_new();
		return this;
	}
	public function p_CompileShader(t_source:String,t_type:int):int{
		return 0;
	}
	internal var m_vertex_id:int=0;
	internal var m_fragment_id:int=0;
	internal var m_shader_id:int=0;
	internal var m_active:int=0;
	public function p_ResetShader():int{
		return 0;
	}
	public static function m_LoadDefaultShader(t_vp_file:String,t_fp_file:String):c_TShader{
		return null;
	}
	internal static var m_default_shader:c_TShader;
	public static function m_SetShader(t_sh:c_TShader):int{
		if((m_g_shader)!=null){
			m_g_shader.m_active=0;
		}
		m_g_shader=t_sh;
		m_g_shader.m_active=1;
		return 0;
	}
	public static function m_LoadDefaultShader2(t_sh:c_TShader):void{
		m_default_shader=t_sh;
		m_SetShader(m_default_shader);
	}
	public static function m_DefaultShader():c_TShader{
		if(!((m_g_shader)!=null)){
			return null;
		}
		m_g_shader.m_active=0;
		m_g_shader=m_default_shader;
		m_g_shader.m_active=1;
		return m_default_shader;
	}
	public function p_Update():int{
		return 0;
	}
	public override function p_Copy():c_TBrush{
		return null;
	}
	internal var m_override:Boolean=false;
}
class c_List6 extends Object{
	public function m_List_new():c_List6{
		return this;
	}
	internal var m__head:c_Node8=((new c_HeadNode6).m_HeadNode_new());
	public function p_AddLast6(t_data:c_TShader):c_Node8{
		return (new c_Node8).m_Node_new(m__head,m__head.m__pred,t_data);
	}
	public function m_List_new2(t_data:Array):c_List6{
		var t_:Array=t_data;
		var t_2:int=0;
		while(t_2<t_.length){
			var t_t:c_TShader=t_[t_2];
			t_2=t_2+1;
			this.p_AddLast6(t_t);
		}
		return this;
	}
	public function p_ObjectEnumerator():c_Enumerator5{
		return (new c_Enumerator5).m_Enumerator_new(this);
	}
}
class c_Node8 extends Object{
	internal var m__succ:c_Node8=null;
	internal var m__pred:c_Node8=null;
	internal var m__data:c_TShader=null;
	public function m_Node_new(t_succ:c_Node8,t_pred:c_Node8,t_data:c_TShader):c_Node8{
		m__succ=t_succ;
		m__pred=t_pred;
		m__succ.m__pred=this;
		m__pred.m__succ=this;
		m__data=t_data;
		return this;
	}
	public function m_Node_new2():c_Node8{
		return this;
	}
}
class c_HeadNode6 extends c_Node8{
	public function m_HeadNode_new():c_HeadNode6{
		super.m_Node_new2();
		m__succ=(this);
		m__pred=(this);
		return this;
	}
}
class c_Enumerator5 extends Object{
	internal var m__list:c_List6=null;
	internal var m__curr:c_Node8=null;
	public function m_Enumerator_new(t_list:c_List6):c_Enumerator5{
		m__list=t_list;
		m__curr=t_list.m__head.m__succ;
		return this;
	}
	public function m_Enumerator_new2():c_Enumerator5{
		return this;
	}
	public function p_HasNext():Boolean{
		while(m__curr.m__succ.m__pred!=m__curr){
			m__curr=m__curr.m__succ;
		}
		return m__curr!=m__list.m__head;
	}
	public function p_NextObject():c_TShader{
		var t_data:c_TShader=m__curr.m__data;
		m__curr=m__curr.m__succ;
		return t_data;
	}
}
interface c_IShaderProcess{
	function p_PreProcess(t_cam:c_TCamera):int;
	function p_PostProcess(t_cam:c_TCamera):int;
}
interface c_IShaderRender extends c_IShaderProcess{
	function p_Render3(t_cam:c_TCamera):int;
}
class c_TLight extends c_TEntity{
	internal static var m_light_list:c_List7;
	internal static var m_no_lights:int;
	internal static var m_max_lights:int;
	public function m_TLight_new():c_TLight{
		super.m_TEntity_new();
		return this;
	}
	internal var m_light_type:int=0;
	internal var m_light_link:c_Node9=null;
	internal var m_const_att:Number=0.5;
	internal var m_lin_att:Number=1.0;
	public static function m_CreateLight(t_l_type:int,t_parent_ent:c_TEntity):c_TLight{
		if(m_no_lights>=m_max_lights){
			return null;
		}
		var t_light:c_TLight=(new c_TLight).m_TLight_new();
		t_light.m_light_type=t_l_type;
		t_light.m_classname="Light";
		m_no_lights=m_no_lights+1;
		t_light.m_light_link=m_light_list.p_AddLast7(t_light);
		t_light.m_entity_link=c_TEntity.m_entity_list.p_EntityListAdd(t_light);
		if((t_parent_ent)!=null){
			t_light.p_AddParent(t_parent_ent);
		}
		if(t_light.m_light_type==1){
			t_light.m_const_att=10.0;
			t_light.m_lin_att=10.0;
		}
		if(t_light.m_parent!=null){
			t_light.m_mat.p_Overwrite(t_light.m_parent.m_mat);
			t_light.p_UpdateMat(false);
		}else{
			t_light.p_UpdateMat(true);
		}
		return t_light;
	}
	internal static var m_ambient_red:Number;
	internal static var m_ambient_green:Number;
	internal static var m_ambient_blue:Number;
	internal var m_red:Number=1.0;
	internal var m_green:Number=1.0;
	internal var m_blue:Number=1.0;
	internal var m_quad_att:Number=0.0;
	internal var m_actual_range:Number=1000.0;
}
class c_List7 extends Object{
	public function m_List_new():c_List7{
		return this;
	}
	internal var m__head:c_Node9=((new c_HeadNode7).m_HeadNode_new());
	public function p_AddLast7(t_data:c_TLight):c_Node9{
		return (new c_Node9).m_Node_new(m__head,m__head.m__pred,t_data);
	}
	public function m_List_new2(t_data:Array):c_List7{
		var t_:Array=t_data;
		var t_2:int=0;
		while(t_2<t_.length){
			var t_t:c_TLight=t_[t_2];
			t_2=t_2+1;
			this.p_AddLast7(t_t);
		}
		return this;
	}
	public function p_ObjectEnumerator():c_Enumerator6{
		return (new c_Enumerator6).m_Enumerator_new(this);
	}
	public function p_IsEmpty():Boolean{
		return m__head.m__succ==m__head;
	}
	public function p_First():c_TLight{
		return m__head.m__succ.m__data;
	}
}
class c_Node9 extends Object{
	internal var m__succ:c_Node9=null;
	internal var m__pred:c_Node9=null;
	internal var m__data:c_TLight=null;
	public function m_Node_new(t_succ:c_Node9,t_pred:c_Node9,t_data:c_TLight):c_Node9{
		m__succ=t_succ;
		m__pred=t_pred;
		m__succ.m__pred=this;
		m__pred.m__succ=this;
		m__data=t_data;
		return this;
	}
	public function m_Node_new2():c_Node9{
		return this;
	}
}
class c_HeadNode7 extends c_Node9{
	public function m_HeadNode_new():c_HeadNode7{
		super.m_Node_new2();
		m__succ=(this);
		m__pred=(this);
		return this;
	}
}
class c_Enumerator6 extends Object{
	internal var m__list:c_List7=null;
	internal var m__curr:c_Node9=null;
	public function m_Enumerator_new(t_list:c_List7):c_Enumerator6{
		m__list=t_list;
		m__curr=t_list.m__head.m__succ;
		return this;
	}
	public function m_Enumerator_new2():c_Enumerator6{
		return this;
	}
	public function p_HasNext():Boolean{
		while(m__curr.m__succ.m__pred!=m__curr){
			m__curr=m__curr.m__succ;
		}
		return m__curr!=m__list.m__head;
	}
	public function p_NextObject():c_TLight{
		var t_data:c_TLight=m__curr.m__data;
		m__curr=m__curr.m__succ;
		return t_data;
	}
}
class c_RenderAlphaList extends c_List3{
	public function m_RenderAlphaList_new():c_RenderAlphaList{
		super.m_List_new();
		return this;
	}
	public override function p_Compare2(t_left:c_TMesh,t_right:c_TMesh):int{
		if(t_left.m_alpha_order>t_right.m_alpha_order){
			return -1;
		}
		return ((t_left.m_alpha_order<t_right.m_alpha_order)?1:0);
	}
}
class c_Enumerator7 extends Object{
	internal var m__list:c_List=null;
	internal var m__curr:c_Node2=null;
	public function m_Enumerator_new(t_list:c_List):c_Enumerator7{
		m__list=t_list;
		m__curr=t_list.m__head.m__succ;
		return this;
	}
	public function m_Enumerator_new2():c_Enumerator7{
		return this;
	}
	public function p_HasNext():Boolean{
		while(m__curr.m__succ.m__pred!=m__curr){
			m__curr=m__curr.m__succ;
		}
		return m__curr!=m__list.m__head;
	}
	public function p_NextObject():c_TEntity{
		var t_data:c_TEntity=m__curr.m__data;
		m__curr=m__curr.m__succ;
		return t_data;
	}
}
class c_Enumerator8 extends Object{
	internal var m__list:c_List2=null;
	internal var m__curr:c_Node3=null;
	public function m_Enumerator_new(t_list:c_List2):c_Enumerator8{
		m__list=t_list;
		m__curr=t_list.m__head.m__succ;
		return this;
	}
	public function m_Enumerator_new2():c_Enumerator8{
		return this;
	}
	public function p_HasNext():Boolean{
		while(m__curr.m__succ.m__pred!=m__curr){
			m__curr=m__curr.m__succ;
		}
		return m__curr!=m__list.m__head;
	}
	public function p_NextObject():c_TSurface{
		var t_data:c_TSurface=m__curr.m__data;
		m__curr=m__curr.m__succ;
		return t_data;
	}
}
class c_VertexDataBuffer extends Object{
	public function m_VertexDataBuffer_new():c_VertexDataBuffer{
		return this;
	}
	internal var m_buf:c_DataBuffer=null;
	public function p_GetVertCoords(t_vec:c_Vector,t_vid:int):void{
		var t_v:int=t_vid*64+0;
		t_vec.m_x=m_buf.PeekFloat(t_v+0);
		t_vec.m_y=m_buf.PeekFloat(t_v+4);
		t_vec.m_z=m_buf.PeekFloat(t_v+8);
	}
	public static function m_Create(t_i:int):c_VertexDataBuffer{
		var t_b:c_VertexDataBuffer=(new c_VertexDataBuffer).m_VertexDataBuffer_new();
		t_b.m_buf=bb_monkeybuffer_CreateDataBuffer((t_i+1)*64);
		Driver3D.DataBufferLittleEndian(t_b.m_buf);
		return t_b;
	}
	public function p_PokeFloatArray(t_i:int,t_arr:Array,t_len:int):void{
		if(t_len==-1){
			t_len=t_arr.length;
		}
		for(var t_v:int=0;t_v<=t_len-1;t_v=t_v+1){
			m_buf.PokeFloat(t_i*64+t_v*4,t_arr[t_v]);
		}
	}
	public function p_PokeNormals(t_i:int,t_x:Number,t_y:Number,t_z:Number):int{
		var t_index:int=t_i*64+16;
		m_buf.PokeFloat(t_index,t_x);
		m_buf.PokeFloat(t_index+4,t_y);
		m_buf.PokeFloat(t_index+8,t_z);
		return 0;
	}
	public function p_PokeTexCoords0(t_i:int,t_s0:Number,t_t0:Number):int{
		var t_index:int=t_i*64+48;
		m_buf.PokeFloat(t_index,t_s0);
		m_buf.PokeFloat(t_index+4,t_t0);
		return 0;
	}
	public function p_PokeTexCoords1(t_i:int,t_s1:Number,t_t1:Number):int{
		var t_index:int=t_i*64+48;
		m_buf.PokeFloat(t_index+8,t_s1);
		m_buf.PokeFloat(t_index+12,t_t1);
		return 0;
	}
	public function p_VertexX(t_vid:int):Number{
		return m_buf.PeekFloat(t_vid*64+0+0);
	}
	public function p_VertexY(t_vid:int):Number{
		return m_buf.PeekFloat(t_vid*64+0+4);
	}
	public function p_VertexZ(t_vid:int):Number{
		return m_buf.PeekFloat(t_vid*64+0+8);
	}
	public function p_PeekVertCoords(t_vid:int):c_Vector{
		var t_v:int=t_vid*64+0;
		return (new c_Vector).m_Vector_new(m_buf.PeekFloat(t_v+0),m_buf.PeekFloat(t_v+4),m_buf.PeekFloat(t_v+8));
	}
	public function p_PokeVertCoords(t_i:int,t_x:Number,t_y:Number,t_z:Number):int{
		var t_index:int=t_i*64+0;
		m_buf.PokeFloat(t_index,t_x);
		m_buf.PokeFloat(t_index+4,t_y);
		m_buf.PokeFloat(t_index+8,t_z);
		return 0;
	}
	public function p_PokeColor(t_i:int,t_r:Number,t_g:Number,t_b:Number,t_a:Number):int{
		var t_index:int=t_i*64+32;
		m_buf.PokeFloat(t_index,t_r);
		m_buf.PokeFloat(t_index+4,t_g);
		m_buf.PokeFloat(t_index+8,t_b);
		m_buf.PokeFloat(t_index+12,t_a);
		return 0;
	}
}
class c_DataBuffer extends BBDataBuffer{
	public function m_DataBuffer_new(t_length:int):c_DataBuffer{
		if(!this._New(t_length)){
			error("Allocate DataBuffer failed");
		}
		return this;
	}
	public function m_DataBuffer_new2():c_DataBuffer{
		return this;
	}
}
internal function bb_math2_Abs(t_x:int):int{
	if(t_x>=0){
		return t_x;
	}
	return -t_x;
}
internal function bb_math2_Abs2(t_x:Number):Number{
	if(t_x>=0.0){
		return t_x;
	}
	return -t_x;
}
interface c_IRenderUpdate{
	function p_Update2(t_cam:c_TCamera):int;
}
class c_Enumerator9 extends Object{
	internal var m__list:c_List3=null;
	internal var m__curr:c_Node4=null;
	public function m_Enumerator_new(t_list:c_List3):c_Enumerator9{
		m__list=t_list;
		m__curr=t_list.m__head.m__succ;
		return this;
	}
	public function m_Enumerator_new2():c_Enumerator9{
		return this;
	}
	public function p_HasNext():Boolean{
		while(m__curr.m__succ.m__pred!=m__curr){
			m__curr=m__curr.m__succ;
		}
		return m__curr!=m__list.m__head;
	}
	public function p_NextObject():c_TMesh{
		var t_data:c_TMesh=m__curr.m__data;
		m__curr=m__curr.m__succ;
		return t_data;
	}
}
internal function bb_monkeybuffer_CreateDataBuffer(t_i:int):c_DataBuffer{
	return (new c_DataBuffer).m_DataBuffer_new(t_i);
}
internal function bb_monkeybuffer_GetBufferLength(t_buf:c_DataBuffer):int{
	return t_buf.Length();
}
internal function bb_monkeybuffer_CopyDataBuffer(t_src:c_DataBuffer,t_dest:c_DataBuffer):c_DataBuffer{
	if(t_src==null){
		return t_dest;
	}
	var t_size:int=bb_monkeybuffer_GetBufferLength(t_src);
	if(bb_monkeybuffer_GetBufferLength(t_dest)<t_size){
		t_size=bb_monkeybuffer_GetBufferLength(t_dest);
	}
	for(var t_i:int=0;t_i<=t_size-1;t_i=t_i+1){
		t_dest.PokeByte(t_i,t_src.PeekByte(t_i));
	}
	return t_dest;
}
internal function bb_monkeybuffer_CopyDataBuffer2(t_src:c_VertexDataBuffer,t_dest:c_VertexDataBuffer):c_VertexDataBuffer{
	if(t_src.m_buf==null){
		return t_dest;
	}
	var t_size:int=bb_monkeybuffer_GetBufferLength(t_src.m_buf);
	if(bb_monkeybuffer_GetBufferLength(t_dest.m_buf)<t_size){
		t_size=bb_monkeybuffer_GetBufferLength(t_dest.m_buf);
	}
	for(var t_i:int=0;t_i<=t_size-1;t_i=t_i+4){
		t_dest.m_buf.PokeInt(t_i,t_src.m_buf.PeekInt(t_i));
	}
	return t_dest;
}
internal function bb_monkeybuffer_CopyDataBuffer3(t_src:c_VertexDataBuffer,t_dest:c_VertexDataBuffer,t_begin:int,t_bend:int):c_VertexDataBuffer{
	if(t_src.m_buf==null){
		return t_dest;
	}
	t_begin*=64;
	t_bend*=64;
	if(t_begin==0 && t_bend==0){
		t_bend=bb_monkeybuffer_GetBufferLength(t_src.m_buf)-1;
	}
	if(bb_monkeybuffer_GetBufferLength(t_dest.m_buf)-1<t_bend){
		t_bend=bb_monkeybuffer_GetBufferLength(t_dest.m_buf)-1;
	}
	for(var t_i:int=t_begin;t_i<=t_bend;t_i=t_i+4){
		t_dest.m_buf.PokeInt(t_i,t_src.m_buf.PeekInt(t_i));
	}
	return t_dest;
}
class c_ShortBuffer extends Object{
	public function m_ShortBuffer_new():c_ShortBuffer{
		return this;
	}
	internal static var m_i2f:c_DataBuffer;
	internal var m_buf:c_DataBuffer=null;
	public static function m_Create(t_i:int):c_ShortBuffer{
		m_i2f=bb_monkeybuffer_CreateDataBuffer(4);
		var t_b:c_ShortBuffer=(new c_ShortBuffer).m_ShortBuffer_new();
		t_b.m_buf=bb_monkeybuffer_CreateDataBuffer(t_i*2+1);
		Driver3D.DataBufferLittleEndian(t_b.m_buf);
		return t_b;
	}
	public function p_Length2():int{
		return (((bb_monkeybuffer_GetBufferLength(m_buf))*0.5)|0);
	}
	public function p_Peek(t_i:int):int{
		return m_buf.PeekShort(t_i*2);
	}
	public function p_Poke(t_i:int,t_arr:Array,t_len:int):void{
		if(t_len==-1){
			t_len=t_arr.length;
		}
		for(var t_v:int=0;t_v<=t_len-1;t_v=t_v+1){
			m_buf.PokeShort((t_i+t_v)*2,t_arr[t_v]);
		}
	}
	public function p_Poke2(t_i:int,t_v:int):void{
		m_buf.PokeShort(t_i*2,t_v);
	}
}
internal function bb_monkeybuffer_CopyShortBuffer(t_src:c_ShortBuffer,t_dest:c_ShortBuffer):c_ShortBuffer{
	if(t_src==null || t_src.m_buf==null){
		return t_dest;
	}
	var t_size:int=t_src.p_Length2();
	if(t_dest.p_Length2()<t_size){
		t_size=t_dest.p_Length2();
	}
	for(var t_i:int=0;t_i<=t_size-1;t_i=t_i+1){
		t_dest.p_Poke2(t_i,t_src.p_Peek(t_i));
	}
	return t_dest;
}
internal function bb_monkeyutility_AllocateFloatArray(t_i:int,t_j:int):Array{
	var t_arr:Array=new_array_array(t_i);
	for(var t_ind:int=0;t_ind<t_i;t_ind=t_ind+1){
		t_arr[t_ind]=new_number_array(t_j);
	}
	return t_arr;
}
class c_TSprite extends c_TMesh implements c_IRenderUpdate{
	internal var m_pixel_scale:Array=new_number_array(2);
	internal var m_mat_sp:c_Matrix=(new c_Matrix).m_Matrix_new();
	public function m_TSprite_new():c_TSprite{
		super.m_TMesh_new();
		m_is_sprite=true;
		return this;
	}
	public static function m_CreateSprite(t_parent_ent:c_TEntity):c_TSprite{
		var t_sprite:c_TSprite=(new c_TSprite).m_TSprite_new();
		t_sprite.m_classname="Sprite";
		t_sprite.p_AddParent(t_parent_ent);
		t_sprite.m_entity_link=c_TEntity.m_entity_list.p_EntityListAdd(t_sprite);
		if(t_sprite.m_parent!=null){
			t_sprite.m_mat.p_Overwrite(t_sprite.m_parent.m_mat);
			t_sprite.p_UpdateMat(false);
		}else{
			t_sprite.p_UpdateMat(true);
		}
		var t_surf:c_TSurface=t_sprite.p_CreateSurface(null);
		t_surf.m_vert_data=c_VertexDataBuffer.m_Create(4);
		t_surf.m_vert_array_size=5;
		t_surf.m_tris=c_ShortBuffer.m_Create(12);
		t_surf.m_tri_array_size=5;
		t_surf.p_AddVertex2([-1.0,-1.0,0.0,0.0,1.0,1.0,1.0,0.0,1.0,1.0,1.0,1.0,0.0,1.0,0.0,1.0,-1.0,1.0,0.0,0.0,1.0,1.0,1.0,0.0,1.0,1.0,1.0,1.0,0.0,0.0,0.0,0.0,1.0,1.0,0.0,0.0,1.0,1.0,1.0,0.0,1.0,1.0,1.0,1.0,1.0,0.0,1.0,0.0,1.0,-1.0,0.0,0.0,1.0,1.0,1.0,0.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0],-1);
		t_surf.p_AddTriangle2([0,1,2,0,2,3],-1);
		t_sprite.p_EntityFX(1);
		return t_sprite;
	}
	public function p_AutoResizeTexture(t_tex:c_TTexture):void{
		var t_x:Number=1.0;
		var t_y:Number=1.0;
		if(t_tex.m_orig_height>t_tex.m_orig_width){
			t_y=(t_tex.m_orig_height)/(t_tex.m_orig_width);
		}
		if(t_tex.m_orig_height<t_tex.m_orig_width){
			t_x=(t_tex.m_orig_width)/(t_tex.m_orig_height);
		}
		this.p_GetSurface(1).p_VertexCoords(0,-t_x,-t_y,0.0);
		this.p_GetSurface(1).p_VertexCoords(1,-t_x,t_y,0.0);
		this.p_GetSurface(1).p_VertexCoords(2,t_x,t_y,0.0);
		this.p_GetSurface(1).p_VertexCoords(3,t_x,-t_y,0.0);
	}
	public static function m_CreateSprite2(t_tex:c_TTexture,t_parent_ent:c_TEntity):c_TSprite{
		var t_sprite:c_TSprite=m_CreateSprite(t_parent_ent);
		t_sprite.p_EntityTexture(t_tex,0,0);
		if((t_tex.m_flags&2)==0 && (t_tex.m_flags&4)==0){
			t_sprite.p_EntityBlend(3);
		}
		if(t_tex.m_orig_width!=0){
			t_sprite.p_AutoResizeTexture(t_tex);
		}
		return t_sprite;
	}
	internal var m_scale_x:Number=1.0;
	internal var m_scale_y:Number=1.0;
	public function p_ScaleSprite(t_s_x:Number,t_s_y:Number):c_TEntity{
		m_scale_x=t_s_x;
		m_scale_y=t_s_y;
		if((m_parent)!=null){
			m_gsx=t_s_x*m_parent.m_gsx;
			m_gsy=t_s_y*m_parent.m_gsy;
			m_gsz=m_gsx;
		}else{
			m_gsx=t_s_x;
			m_gsy=t_s_y;
			m_gsz=m_gsx;
		}
		return (this);
	}
	public override function p_ScaleEntity(t_x:Number,t_y:Number,t_z:Number,t_glob:int):c_TEntity{
		this.p_ScaleSprite(t_x,t_y);
		return (this);
	}
	internal var m_view_mode:int=1;
	internal static var m_temp_mat:c_Matrix;
	internal var m_angle:Number=.0;
	internal var m_handle_x:Number=.0;
	internal var m_handle_y:Number=.0;
	public function p_Update2(t_cam:c_TCamera):int{
		if(m_view_mode!=2){
			var t_x:Number=m_mat.m_grid[3][0];
			var t_y:Number=m_mat.m_grid[3][1];
			var t_z:Number=m_mat.m_grid[3][2];
			m_temp_mat.p_Overwrite(t_cam.m_mat);
			m_temp_mat.m_grid[3][0]=t_x;
			m_temp_mat.m_grid[3][1]=t_y;
			m_temp_mat.m_grid[3][2]=t_z;
			m_mat_sp.p_Overwrite(m_temp_mat);
			if(m_angle!=0.0){
				m_mat_sp.p_RotateRoll(m_angle);
			}
			if(m_scale_x!=1.0 || m_scale_y!=1.0){
				m_mat_sp.p_Scale(m_scale_x,m_scale_y,1.0);
			}
			if(m_handle_x!=0.0 || m_handle_y!=0.0){
				m_mat_sp.p_Translate(-m_handle_x,-m_handle_y,0.0);
			}
		}else{
			m_mat_sp.p_Overwrite(m_mat);
			if(m_scale_x!=1.0 || m_scale_y!=1.0){
				m_mat_sp.p_Scale(m_scale_x,m_scale_y,1.0);
			}
		}
		return 0;
	}
}
internal function bb_functions_RenderWorld():int{
	c_TRender.m_RenderWorld();
	return 0;
}
class c_CalLoaderHandler extends Object{
	internal var m_LoaderCallbacks:c_List8=null;
	public function m_CalLoaderHandler_new():c_CalLoaderHandler{
		m_LoaderCallbacks=(new c_List8).m_List_new();
		return this;
	}
	public function p_LoadFile(t_url:String,t_type:int,t_loader:c_CalLoader,t_data:String):int{
		var t_callback:c_CalLoadingCallback=(new c_CalLoadingCallback).m_CalLoadingCallback_new();
		t_callback.p_SetLoader(t_loader);
		t_callback.p_Load(t_type,t_url,t_data,"text/plain;charset=utf-8","utf8");
		m_LoaderCallbacks.p_AddLast8(t_callback);
		return 0;
	}
	public function p_IsFileLoaded(t_url:String):Boolean{
		var t_:c_Enumerator12=m_LoaderCallbacks.p_ObjectEnumerator();
		while(t_.p_HasNext()){
			var t_callback:c_CalLoadingCallback=t_.p_NextObject();
			if(t_callback.m_fileurl==t_url && t_callback.p_IsFinished()==true && t_callback.m_loader.p_IsLoaded2()==true){
				return true;
			}
		}
		return false;
	}
	public function p_GetLoadedFile(t_url:String,t_keepinlist:Boolean):Object{
		var t_:c_Enumerator12=m_LoaderCallbacks.p_ObjectEnumerator();
		while(t_.p_HasNext()){
			var t_callback:c_CalLoadingCallback=t_.p_NextObject();
			if(t_callback.m_fileurl==t_url && t_callback.p_IsFinished()==true && t_callback.m_loader.p_IsLoaded2()==true){
				if(t_keepinlist==false){
					m_LoaderCallbacks.p_Remove3(t_callback);
				}
				return t_callback.p_GetLoadedObject();
			}
		}
		return null;
	}
	public function p_Update():int{
		var t_:c_Enumerator12=m_LoaderCallbacks.p_ObjectEnumerator();
		while(t_.p_HasNext()){
			var t_callback:c_CalLoadingCallback=t_.p_NextObject();
			t_callback.p_Update();
			if(t_callback.p_IsFinished()==true && t_callback.m_loader.p_IsLoaded2()==false){
				t_callback.m_loader.p_Load2(t_callback.m_data);
			}
		}
		return 0;
	}
}
interface c_IOnHttpRequestComplete{
	function p_OnHttpRequestComplete(t_req:c_HttpRequest):void;
}
class c_CalLoadingCallback extends Object implements c_IOnHttpRequestComplete{
	public function m_CalLoadingCallback_new():c_CalLoadingCallback{
		return this;
	}
	internal var m_loader:c_CalLoader=null;
	public function p_SetLoader(t_loadr:c_CalLoader):void{
		m_loader=t_loadr;
	}
	internal var m_fileurl:String="";
	internal var m_get_req:c_HttpRequest=null;
	internal var m_hasheader:Boolean=false;
	internal var m_headername:String="";
	internal var m_headerval:String="";
	internal var m_post_req:c_HttpRequest=null;
	public function p_Load(t_type:int,t_url:String,t_data:String,t_mime:String,t_enc:String):void{
		m_fileurl=t_url;
		print("Loading: "+t_url);
		var t_1:int=t_type;
		if(t_1==0){
			m_get_req=(new c_HttpRequest).m_HttpRequest_new2("GET",t_url,(this));
			if(m_hasheader==true){
				m_get_req.p_SetHeader(m_headername,m_headerval);
			}
			if(t_data!=""){
				m_get_req.p_Send2(t_data,t_mime,t_enc);
			}else{
				m_get_req.p_Send();
			}
		}else{
			if(t_1==1){
				m_post_req=(new c_HttpRequest).m_HttpRequest_new2("POST",t_url,(this));
				if(m_hasheader==true){
					m_post_req.p_SetHeader(m_headername,m_headerval);
				}
				if(t_data!=""){
					m_post_req.p_Send2(t_data,t_mime,t_enc);
				}else{
					m_post_req.p_Send();
				}
			}
		}
	}
	internal var m_finished:Boolean=false;
	public function p_IsFinished():Boolean{
		return m_finished;
	}
	public function p_GetLoadedObject():Object{
		return m_loader.p_GetLoadedObject();
	}
	internal var m_bytesrec:int=0;
	public function p_Update():void{
		if(m_get_req!=null){
			m_bytesrec=m_get_req.p_BytesReceived();
		}
		if(m_post_req!=null){
			m_bytesrec=m_post_req.p_BytesReceived();
		}
	}
	internal var m_data:String="";
	public function p_OnHttpRequestComplete(t_req:c_HttpRequest):void{
		print("Status: "+String(t_req.p_Status()));
		m_data=t_req.p_ResponseText();
		m_finished=true;
	}
}
class c_List8 extends Object{
	public function m_List_new():c_List8{
		return this;
	}
	internal var m__head:c_Node10=((new c_HeadNode8).m_HeadNode_new());
	public function p_AddLast8(t_data:c_CalLoadingCallback):c_Node10{
		return (new c_Node10).m_Node_new(m__head,m__head.m__pred,t_data);
	}
	public function m_List_new2(t_data:Array):c_List8{
		var t_:Array=t_data;
		var t_2:int=0;
		while(t_2<t_.length){
			var t_t:c_CalLoadingCallback=t_[t_2];
			t_2=t_2+1;
			this.p_AddLast8(t_t);
		}
		return this;
	}
	public function p_ObjectEnumerator():c_Enumerator12{
		return (new c_Enumerator12).m_Enumerator_new(this);
	}
	public function p_Equals2(t_lhs:c_CalLoadingCallback,t_rhs:c_CalLoadingCallback):Boolean{
		return t_lhs==t_rhs;
	}
	public function p_RemoveEach2(t_value:c_CalLoadingCallback):int{
		var t_node:c_Node10=m__head.m__succ;
		while(t_node!=m__head){
			var t_succ:c_Node10=t_node.m__succ;
			if(this.p_Equals2(t_node.m__data,t_value)){
				t_node.p_Remove();
			}
			t_node=t_succ;
		}
		return 0;
	}
	public function p_Remove3(t_value:c_CalLoadingCallback):void{
		this.p_RemoveEach2(t_value);
	}
}
class c_Node10 extends Object{
	internal var m__succ:c_Node10=null;
	internal var m__pred:c_Node10=null;
	internal var m__data:c_CalLoadingCallback=null;
	public function m_Node_new(t_succ:c_Node10,t_pred:c_Node10,t_data:c_CalLoadingCallback):c_Node10{
		m__succ=t_succ;
		m__pred=t_pred;
		m__succ.m__pred=this;
		m__pred.m__succ=this;
		m__data=t_data;
		return this;
	}
	public function m_Node_new2():c_Node10{
		return this;
	}
	public function p_Remove():int{
		m__succ.m__pred=m__pred;
		m__pred.m__succ=m__succ;
		return 0;
	}
}
class c_HeadNode8 extends c_Node10{
	public function m_HeadNode_new():c_HeadNode8{
		super.m_Node_new2();
		m__succ=(this);
		m__pred=(this);
		return this;
	}
}
class c_CalLoader extends Object{
	public function m_CalLoader_new():c_CalLoader{
		return this;
	}
	internal var m_loaded:Boolean=false;
	public function p_IsLoaded2():Boolean{
		return m_loaded;
	}
	internal var m_loadedobject:Object=null;
	public function p_GetLoadedObject():Object{
		return m_loadedobject;
	}
	public function p_Load2(t_data:String):Object{
		m_loadedobject=(new Object);
		m_loaded=true;
		return m_loadedobject;
	}
}
class c_SKNCalSkeletonLoader extends c_CalLoader{
	public function m_SKNCalSkeletonLoader_new():c_SKNCalSkeletonLoader{
		super.m_CalLoader_new();
		return this;
	}
	public override function p_Load2(t_data:String):Object{
		var t_isimvu:Boolean=false;
		var t_error:c_XMLError=(new c_XMLError).m_XMLError_new();
		var t_doc:c_XMLDoc=bb_xml_ParseXML(t_data,t_error,1);
		if(t_doc==null && t_error.m_error){
			print(t_error.p_ToString());
			m_loaded=true;
			return null;
		}
		var t_skeletonElem:c_XMLNode=(t_doc);
		if(t_skeletonElem==null){
			print("Skeleton Node not found!");
			m_loaded=true;
			return null;
		}
		if(t_skeletonElem.m_name!="skeleton"){
			if(t_skeletonElem.m_name=="header"){
				t_skeletonElem=t_skeletonElem.p_GetChild(false);
				t_isimvu=true;
				if(t_skeletonElem.m_name!="skeleton"){
					print("Wrong Start Node: "+t_skeletonElem.m_name);
					m_loaded=true;
					return null;
				}
			}else{
				print("Wrong Start Node: "+t_skeletonElem.m_name);
				m_loaded=true;
				return null;
			}
		}
		if(t_skeletonElem.p_GetXMLAttribute("version").m_value!="1000" && t_isimvu==false){
			print("Wrong Version: "+t_skeletonElem.p_GetXMLAttribute("version").m_value);
			return null;
		}
		var t_coreSkeleton:c_CalCoreSkeleton=(new c_CalCoreSkeleton).m_CalCoreSkeleton_new();
		var t_boneCount:int=parseInt((t_skeletonElem.p_GetXMLAttribute("numbones").m_value),10);
		var t_boneids:c_List13=t_skeletonElem.p_GetChildren2("bone",null,false);
		var t_:c_Enumerator14=t_boneids.p_ObjectEnumerator();
		while(t_.p_HasNext()){
			var t_boneElem:c_XMLNode=t_.p_NextObject();
			var t_name:String=t_boneElem.p_GetXMLAttribute("name").m_value;
			var t_translationElem:c_XMLNode=t_boneElem.p_GetChild2("translation",false);
			if(t_translationElem==null){
				print("No Translation bone data");
				return null;
			}
			var t_r:Array=t_translationElem.m_value.split(" ");
			var t_tx:Number=.0;
			var t_ty:Number=.0;
			var t_tz:Number=.0;
			t_tx=parseFloat(t_r[0]);
			t_ty=parseFloat(t_r[1]);
			t_tz=parseFloat(t_r[2]);
			var t_rotationElem:c_XMLNode=t_boneElem.p_GetChild2("rotation",false);
			if(t_rotationElem==null){
				print("No Rotation bone data");
				return null;
			}
			var t_rr:Array=t_rotationElem.m_value.split(" ");
			var t_rx:Number=.0;
			var t_ry:Number=.0;
			var t_rz:Number=.0;
			var t_rw:Number=.0;
			t_rx=parseFloat(t_rr[0]);
			t_ry=parseFloat(t_rr[1]);
			t_rz=parseFloat(t_rr[2]);
			t_rw=parseFloat(t_rr[3]);
			var t_translationBoneSpaceElem:c_XMLNode=t_boneElem.p_GetChild2("localtranslation",false);
			if(t_translationBoneSpaceElem==null){
				print("No Local Translation bone data");
				return null;
			}
			var t_txBoneSpace:Number=.0;
			var t_tyBoneSpace:Number=.0;
			var t_tzBoneSpace:Number=.0;
			var t_tl:Array=t_translationBoneSpaceElem.m_value.split(" ");
			t_txBoneSpace=parseFloat(t_tl[0]);
			t_tyBoneSpace=parseFloat(t_tl[1]);
			t_tzBoneSpace=parseFloat(t_tl[2]);
			var t_rotationBoneSpaceElem:c_XMLNode=t_boneElem.p_GetChild2("localrotation",false);
			if(t_rotationBoneSpaceElem==null){
				print("No Local Rotation bone data");
				return null;
			}
			var t_lr:Array=t_rotationBoneSpaceElem.m_value.split(" ");
			var t_rxBoneSpace:Number=.0;
			var t_ryBoneSpace:Number=.0;
			var t_rzBoneSpace:Number=.0;
			var t_rwBoneSpace:Number=.0;
			t_rxBoneSpace=parseFloat(t_lr[0]);
			t_ryBoneSpace=parseFloat(t_lr[1]);
			t_rzBoneSpace=parseFloat(t_lr[2]);
			t_rwBoneSpace=parseFloat(t_lr[3]);
			var t_parentElem:c_XMLNode=t_boneElem.p_GetChild2("parentid",false);
			var t_parentId:int=parseInt((t_parentElem.m_value),10);
			var t_coreBone:c_CalCoreBone=(new c_CalCoreBone).m_CalCoreBone_new(t_name);
			t_coreBone.p_setParentId(t_parentId);
			var t_trans:c_CalVector=(new c_CalVector).m_CalVector_new3(t_tx,t_ty,t_tz);
			var t_rot:c_CalQuaternion=(new c_CalQuaternion).m_CalQuaternion_new3(t_rx,t_ry,t_rz,t_rw);
			t_coreBone.p_setTranslation(t_trans);
			t_coreBone.p_setRotation(t_rot);
			t_coreBone.p_setTranslationBoneSpace((new c_CalVector).m_CalVector_new3(t_txBoneSpace,t_tyBoneSpace,t_tzBoneSpace));
			t_coreBone.p_setRotationBoneSpace((new c_CalQuaternion).m_CalQuaternion_new3(t_rxBoneSpace,t_ryBoneSpace,t_rzBoneSpace,t_rwBoneSpace));
			var t_childids:c_List13=t_boneElem.p_GetChildren2("childid",null,false);
			var t_2:c_Enumerator14=t_childids.p_ObjectEnumerator();
			while(t_2.p_HasNext()){
				var t_childElem:c_XMLNode=t_2.p_NextObject();
				var t_childId:int=parseInt((t_childElem.m_value),10);
				t_coreBone.p_addChildId(t_childId);
			}
			t_coreBone.p_setCoreSkeleton(t_coreSkeleton);
			t_coreSkeleton.p_addCoreBone(t_coreBone);
		}
		t_coreSkeleton.p_calculateState();
		m_loadedobject=(t_coreSkeleton);
		m_loaded=true;
		return m_loadedobject;
	}
}
interface c_IAsyncEventSource{
	function p_UpdateAsyncEvents():void;
}
class c_HttpRequest extends Object implements c_IAsyncEventSource{
	public function m_HttpRequest_new():c_HttpRequest{
		return this;
	}
	internal var m__req:BBHttpRequest=null;
	internal var m__onComplete:c_IOnHttpRequestComplete=null;
	public function p_Open(t_req:String,t_url:String,t_onComplete:c_IOnHttpRequestComplete):void{
		if(((m__req)!=null) && m__req.IsRunning()){
			error("HttpRequest in progress");
		}
		m__req=(new BBHttpRequest);
		m__onComplete=t_onComplete;
		m__req.Open(t_req,t_url);
	}
	public function m_HttpRequest_new2(t_req:String,t_url:String,t_onComplete:c_IOnHttpRequestComplete):c_HttpRequest{
		this.p_Open(t_req,t_url,t_onComplete);
		return this;
	}
	public function p_SetHeader(t_name:String,t_value:String):void{
		if(!((m__req)!=null)){
			error("HttpRequest not open");
		}
		if(m__req.IsRunning()){
			error("HttpRequest in progress");
		}
		m__req.SetHeader(t_name,t_value);
	}
	public function p_Send():void{
		if(!((m__req)!=null)){
			error("HttpRequest not open");
		}
		if(m__req.IsRunning()){
			error("HttpRequest in progress");
		}
		bb_asyncevent_AddAsyncEventSource(this);
		m__req.Send();
	}
	public function p_Send2(t_data:String,t_mimeType:String,t_encoding:String):void{
		if(!((m__req)!=null)){
			error("HttpRequest not open");
		}
		if(m__req.IsRunning()){
			error("HttpRequest in progress");
		}
		if((t_mimeType).length!=0){
			m__req.SetHeader("Content-Type",t_mimeType);
		}
		bb_asyncevent_AddAsyncEventSource(this);
		m__req.SendText(t_data,t_encoding);
	}
	public function p_BytesReceived():int{
		if(!((m__req)!=null)){
			error("HttpRequest not open");
		}
		return m__req.BytesReceived();
	}
	public function p_UpdateAsyncEvents():void{
		if(m__req.IsRunning()){
			return;
		}
		bb_asyncevent_RemoveAsyncEventSource(this);
		m__onComplete.p_OnHttpRequestComplete(this);
	}
	public function p_Status():int{
		if(!((m__req)!=null)){
			error("HttpRequest not open");
		}
		return m__req.Status();
	}
	public function p_ResponseText():String{
		if(!((m__req)!=null)){
			error("HttpRequest not open");
		}
		return m__req.ResponseText();
	}
}
class c_Stack4 extends Object{
	public function m_Stack_new():c_Stack4{
		return this;
	}
	internal var m_data:Array=[];
	internal var m_length:int=0;
	public function m_Stack_new2(t_data:Array):c_Stack4{
		this.m_data=t_data.slice(0);
		this.m_length=t_data.length;
		return this;
	}
	public function p_Equals3(t_lhs:c_IAsyncEventSource,t_rhs:c_IAsyncEventSource):Boolean{
		return t_lhs==t_rhs;
	}
	public function p_Contains2(t_value:c_IAsyncEventSource):Boolean{
		for(var t_i:int=0;t_i<m_length;t_i=t_i+1){
			if(this.p_Equals3(m_data[t_i],t_value)){
				return true;
			}
		}
		return false;
	}
	public function p_Push10(t_value:c_IAsyncEventSource):void{
		if(m_length==m_data.length){
			m_data=resize_object_array(m_data,m_length*2+10);
		}
		m_data[m_length]=t_value;
		m_length+=1;
	}
	public function p_Push11(t_values:Array,t_offset:int,t_count:int):void{
		for(var t_i:int=0;t_i<t_count;t_i=t_i+1){
			this.p_Push10(t_values[t_offset+t_i]);
		}
	}
	public function p_Push12(t_values:Array,t_offset:int):void{
		this.p_Push11(t_values,t_offset,t_values.length-t_offset);
	}
	internal static var m_NIL:c_IAsyncEventSource;
	public function p_Length(t_newlength:int):void{
		if(t_newlength<m_length){
			for(var t_i:int=t_newlength;t_i<m_length;t_i=t_i+1){
				m_data[t_i]=m_NIL;
			}
		}else{
			if(t_newlength>m_data.length){
				m_data=resize_object_array(m_data,bb_math2_Max(m_length*2+10,t_newlength));
			}
		}
		m_length=t_newlength;
	}
	public function p_Length2():int{
		return m_length;
	}
	public function p_Get(t_index:int):c_IAsyncEventSource{
		return m_data[t_index];
	}
	public function p_RemoveEach3(t_value:c_IAsyncEventSource):void{
		var t_i:int=0;
		var t_j:int=m_length;
		while(t_i<m_length){
			if(!this.p_Equals3(m_data[t_i],t_value)){
				t_i+=1;
				continue;
			}
			var t_b:int=t_i;
			var t_e:int=t_i+1;
			while(t_e<m_length && this.p_Equals3(m_data[t_e],t_value)){
				t_e+=1;
			}
			while(t_e<m_length){
				m_data[t_b]=m_data[t_e];
				t_b+=1;
				t_e+=1;
			}
			m_length-=t_e-t_b;
			t_i+=1;
		}
		t_i=m_length;
		while(t_i<t_j){
			m_data[t_i]=m_NIL;
			t_i+=1;
		}
	}
}
var bb_asyncevent__sources:c_Stack4;
internal function bb_asyncevent_AddAsyncEventSource(t_source:c_IAsyncEventSource):void{
	if(bb_asyncevent__sources.p_Contains2(t_source)){
		error("Async event source is already active");
	}
	bb_asyncevent__sources.p_Push10(t_source);
}
class c_SKNCalMeshLoader extends c_CalLoader{
	public function m_SKNCalMeshLoader_new():c_SKNCalMeshLoader{
		super.m_CalLoader_new();
		return this;
	}
	public override function p_Load2(t_data:String):Object{
		var t_isimvu:Boolean=false;
		var t_error:c_XMLError=(new c_XMLError).m_XMLError_new();
		var t_doc:c_XMLDoc=bb_xml_ParseXML(t_data,t_error,1);
		if(t_doc==null && t_error.m_error){
			print(t_error.p_ToString());
			m_loaded=true;
			return null;
		}
		var t_meshElem:c_XMLNode=(t_doc);
		if(t_meshElem==null){
			print("Mesh Node not found!");
			m_loaded=true;
			return null;
		}
		if(t_meshElem.m_name!="mesh"){
			if(t_meshElem.m_name=="header"){
				t_meshElem=t_meshElem.p_GetChild(false);
				t_isimvu=true;
				if(t_meshElem.m_name!="mesh"){
					print("Wrong Start Node: "+t_meshElem.m_name);
					m_loaded=true;
					return null;
				}
			}else{
				print("Wrong Start Node: "+t_meshElem.m_name);
				m_loaded=true;
				return null;
			}
		}
		if(t_meshElem.p_GetXMLAttribute("version").m_value!="1000" && t_isimvu==false){
			print("Wrong Version: "+t_meshElem.p_GetXMLAttribute("version").m_value);
			return null;
		}
		var t_submeshCount:int=parseInt((t_meshElem.p_GetXMLAttribute("numsubmesh").m_value),10);
		var t_coreMesh:c_CalCoreMesh=(new c_CalCoreMesh).m_CalCoreMesh_new();
		var t_submeshIds:c_List13=t_meshElem.p_GetChildren2("submesh",null,false);
		var t_:c_Enumerator14=t_submeshIds.p_ObjectEnumerator();
		while(t_.p_HasNext()){
			var t_submeshElem:c_XMLNode=t_.p_NextObject();
			var t_coreMaterialThreadId:int=parseInt((t_submeshElem.p_GetXMLAttribute("material").m_value),10);
			var t_vertexCount:int=parseInt((t_submeshElem.p_GetXMLAttribute("numvertices").m_value),10);
			var t_faceCount:int=parseInt((t_submeshElem.p_GetXMLAttribute("numfaces").m_value),10);
			var t_lodCount:int=parseInt((t_submeshElem.p_GetXMLAttribute("numlodsteps").m_value),10);
			var t_springCount:int=parseInt((t_submeshElem.p_GetXMLAttribute("numsprings").m_value),10);
			var t_textureCoordinateCount:int=parseInt((t_submeshElem.p_GetXMLAttribute("numtexcoords").m_value),10);
			var t_coreSubmesh:c_CalCoreSubmesh=(new c_CalCoreSubmesh).m_CalCoreSubmesh_new();
			t_coreSubmesh.p_setLodCount(t_lodCount);
			t_coreSubmesh.p_setCoreMaterialThreadId(t_coreMaterialThreadId);
			if(t_coreSubmesh.p_reserve(t_vertexCount,t_textureCoordinateCount,t_faceCount,t_springCount)==false){
				print("Could not reserve arrays");
				return null;
			}
			var t_vertIds:c_List13=t_submeshElem.p_GetChildren2("vertex",null,false);
			var t_vertexId:int=0;
			var t_2:c_Enumerator14=t_vertIds.p_ObjectEnumerator();
			while(t_2.p_HasNext()){
				var t_vertexElem:c_XMLNode=t_2.p_NextObject();
				var t_vertex:c_CalVertex=(new c_CalVertex).m_CalVertex_new();
				var t_posElem:c_XMLNode=t_vertexElem.p_GetChild2("pos",false);
				var t_p:Array=t_posElem.m_value.split(" ");
				t_vertex.m_position.m_x=parseFloat(t_p[0]);
				t_vertex.m_position.m_y=parseFloat(t_p[1]);
				t_vertex.m_position.m_z=parseFloat(t_p[2]);
				var t_normElem:c_XMLNode=t_vertexElem.p_GetChild2("norm",false);
				var t_n:Array=t_normElem.m_value.split(" ");
				t_vertex.m_normal.m_x=parseFloat(t_n[0]);
				t_vertex.m_normal.m_y=parseFloat(t_n[1]);
				t_vertex.m_normal.m_z=parseFloat(t_n[2]);
				var t_textureCoordinateId:int=0;
				var t_textcoordsIds:c_List13=t_vertexElem.p_GetChildren2("texcoord",null,false);
				var t_3:c_Enumerator14=t_textcoordsIds.p_ObjectEnumerator();
				while(t_3.p_HasNext()){
					var t_texcoordElem:c_XMLNode=t_3.p_NextObject();
					var t_textureCoordinate:c_CalTextureCoordinate=(new c_CalTextureCoordinate).m_CalTextureCoordinate_new();
					var t_tc:Array=t_texcoordElem.m_value.split(" ");
					t_textureCoordinate.m_u=parseFloat(t_tc[0]);
					t_textureCoordinate.m_v=parseFloat(t_tc[1]);
					t_coreSubmesh.p_setTextureCoordinate(t_vertexId,t_textureCoordinateId,t_textureCoordinate);
					t_textureCoordinateId=t_textureCoordinateId+1;
				}
				var t_influenceIds:c_List13=t_vertexElem.p_GetChildren2("influence",null,false);
				var t_influenceId:int=0;
				var t_4:c_Enumerator14=t_influenceIds.p_ObjectEnumerator();
				while(t_4.p_HasNext()){
					var t_influenceElem:c_XMLNode=t_4.p_NextObject();
					var t_influence:c_CalInfluence=(new c_CalInfluence).m_CalInfluence_new();
					t_influence.m_boneId=parseInt((t_influenceElem.p_GetXMLAttribute("id").m_value),10);
					t_influence.m_weight=parseFloat(t_influenceElem.m_value);
					t_vertex.m_vectorInfluence=resize_object_array(t_vertex.m_vectorInfluence,t_vertex.m_vectorInfluence.length+1);
					t_vertex.m_vectorInfluence[t_vertex.m_vectorInfluence.length-1]=t_influence;
					t_influenceId=t_influenceId+1;
				}
				t_coreSubmesh.p_setVertex(t_vertexId,t_vertex);
				t_vertexId=t_vertexId+1;
			}
			var t_faceId:int=0;
			var t_faceIds:c_List13=t_submeshElem.p_GetChildren2("face",null,false);
			var t_5:c_Enumerator14=t_faceIds.p_ObjectEnumerator();
			while(t_5.p_HasNext()){
				var t_faceElem:c_XMLNode=t_5.p_NextObject();
				var t_face:c_CalFace=(new c_CalFace).m_CalFace_new();
				var t_fi:Array=t_faceElem.p_GetXMLAttribute("vertexid").m_value.split(" ");
				t_face.m_vertexId[0]=parseInt((t_fi[0]),10);
				t_face.m_vertexId[1]=parseInt((t_fi[1]),10);
				t_face.m_vertexId[2]=parseInt((t_fi[2]),10);
				t_coreSubmesh.p_setFace(t_faceId,t_face);
				t_faceId=t_faceId+1;
			}
			t_coreMesh.p_addCoreSubmesh(t_coreSubmesh);
		}
		m_loadedobject=(t_coreMesh);
		m_loaded=true;
		return m_loadedobject;
	}
}
class c_SKNCalAnimationLoader extends c_CalLoader{
	public function m_SKNCalAnimationLoader_new():c_SKNCalAnimationLoader{
		super.m_CalLoader_new();
		return this;
	}
	public override function p_Load2(t_data:String):Object{
		var t_isimvu:Boolean=false;
		var t_error:c_XMLError=(new c_XMLError).m_XMLError_new();
		var t_doc:c_XMLDoc=bb_xml_ParseXML(t_data,t_error,1);
		if(t_doc==null && t_error.m_error){
			print(t_error.p_ToString());
			m_loaded=true;
			return null;
		}
		var t_animationElem:c_XMLNode=(t_doc);
		if(t_animationElem==null){
			print("Animation Node not found!");
			m_loaded=true;
			return null;
		}
		if(t_animationElem.m_name!="animation"){
			if(t_animationElem.m_name=="header"){
				t_animationElem=t_animationElem.p_GetChild(false);
				t_isimvu=true;
				if(t_animationElem.m_name!="animation"){
					print("Wrong Start Node: "+t_animationElem.m_name);
					m_loaded=true;
					return null;
				}
			}else{
				print("Wrong Start Node: "+t_animationElem.m_name);
				m_loaded=true;
				return null;
			}
		}
		if(t_animationElem.p_GetXMLAttribute("version").m_value!="1000" && t_isimvu==false){
			print("Wrong Version: "+t_animationElem.p_GetXMLAttribute("version").m_value);
			return null;
		}
		var t_duration:Number=parseFloat(t_animationElem.p_GetXMLAttribute("duration").m_value);
		var t_trackCount:int=parseInt((t_animationElem.p_GetXMLAttribute("numtracks").m_value),10);
		var t_coreAnimation:c_CalCoreAnimation=(new c_CalCoreAnimation).m_CalCoreAnimation_new();
		if(t_duration<=0.0){
			print("Invalid Duration");
			return null;
		}
		t_coreAnimation.p_setDuration(t_duration);
		var t_trackIds:c_List13=t_animationElem.p_GetChildren2("track",null,false);
		var t_:c_Enumerator14=t_trackIds.p_ObjectEnumerator();
		while(t_.p_HasNext()){
			var t_trackElem:c_XMLNode=t_.p_NextObject();
			var t_coreTrack:c_CalCoreTrack=(new c_CalCoreTrack).m_CalCoreTrack_new();
			var t_coreBoneId:int=parseInt((t_trackElem.p_GetXMLAttribute("boneid").m_value),10);
			t_coreTrack.p_setCoreBoneId(t_coreBoneId);
			var t_keyframeCount:int=parseInt((t_trackElem.p_GetXMLAttribute("numkeyframes").m_value),10);
			var t_keyIds:c_List13=t_trackElem.p_GetChildren2("keyframe",null,false);
			var t_2:c_Enumerator14=t_keyIds.p_ObjectEnumerator();
			while(t_2.p_HasNext()){
				var t_keyframeElem:c_XMLNode=t_2.p_NextObject();
				var t_time:Number=parseFloat(t_keyframeElem.p_GetXMLAttribute("time").m_value);
				var t_translationElem:c_XMLNode=t_keyframeElem.p_GetChild2("translation",false);
				var t_tr:Array=t_translationElem.m_value.split(" ");
				var t_tx:Number=.0;
				var t_ty:Number=.0;
				var t_tz:Number=.0;
				t_tx=parseFloat(t_tr[0]);
				t_ty=parseFloat(t_tr[1]);
				t_tz=parseFloat(t_tr[2]);
				var t_rotationElem:c_XMLNode=t_keyframeElem.p_GetChild2("rotation",false);
				var t_ro:Array=t_rotationElem.m_value.split(" ");
				var t_rx:Number=.0;
				var t_ry:Number=.0;
				var t_rz:Number=.0;
				var t_rw:Number=.0;
				t_rx=parseFloat(t_ro[0]);
				t_ry=parseFloat(t_ro[1]);
				t_rz=parseFloat(t_ro[2]);
				t_rw=parseFloat(t_ro[3]);
				var t_coreKeyframe:c_CalCoreKeyframe=(new c_CalCoreKeyframe).m_CalCoreKeyframe_new();
				t_coreKeyframe.p_setTime(t_time);
				t_coreKeyframe.p_setTranslation((new c_CalVector).m_CalVector_new3(t_tx,t_ty,t_tz));
				t_coreKeyframe.p_setRotation((new c_CalQuaternion).m_CalQuaternion_new3(t_rx,t_ry,t_rz,t_rw));
				t_coreTrack.p_addCoreKeyframe(t_coreKeyframe);
			}
			t_coreAnimation.p_addCoreTrack(t_coreTrack);
		}
		m_loadedobject=(t_coreAnimation);
		m_loaded=true;
		return m_loadedobject;
	}
}
class c_SKNCalImageLoader extends c_CalLoader{
	public function m_SKNCalImageLoader_new():c_SKNCalImageLoader{
		super.m_CalLoader_new();
		return this;
	}
	public override function p_Load2(t_data:String):Object{
		var t_isimvu:Boolean=false;
		var t_error:c_XMLError=(new c_XMLError).m_XMLError_new();
		var t_doc:c_XMLDoc=bb_xml_ParseXML(t_data,t_error,1);
		if(t_doc==null && t_error.m_error){
			print(t_error.p_ToString());
			m_loaded=true;
			return null;
		}
		var t_imageElem:c_XMLNode=(t_doc);
		if(t_imageElem==null){
			print("Image Node not found!");
			m_loaded=true;
			return null;
		}
		if(t_imageElem.m_name!="image"){
			print("Wrong Start Node: "+t_imageElem.m_name);
			m_loaded=true;
			return null;
		}
		var t_cimg:c_CalImage=(new c_CalImage).m_CalImage_new2(parseInt((t_imageElem.p_GetXMLAttribute("width").m_value),10),parseInt((t_imageElem.p_GetXMLAttribute("height").m_value),10),bb_sknxmlloader_mysplit(t_imageElem.m_value,"|"));
		m_loadedobject=(t_cimg);
		m_loaded=true;
		return m_loadedobject;
	}
}
class c_Cal3dB3d extends Object{
	internal var m_B3dModel:c_TMesh=null;
	internal var m_Meshes:c_List9=null;
	internal var m_Anims:c_List10=null;
	internal var m_CoreModel:c_CalCoreModel=null;
	public function m_Cal3dB3d_new():c_Cal3dB3d{
		m_B3dModel=c_TMesh.m_CreateMesh(null);
		m_Meshes=(new c_List9).m_List_new();
		m_Anims=(new c_List10).m_List_new();
		m_CoreModel=(new c_CalCoreModel).m_CalCoreModel_new("Model");
		return this;
	}
	internal var m_isloaded:Boolean=false;
	internal var m_Skele:c_CalCoreSkeleton=null;
	public function p_SetSkeleton(t_skel:c_CalCoreSkeleton):int{
		m_Skele=t_skel;
		m_CoreModel.p_setCoreSkeleton(m_Skele);
		return 0;
	}
	public function p_AddMesh(t_msh:c_CalCoreMesh):int{
		if(t_msh!=null){
			var t_c3db3dm:c_Cal3dB3dMesh=(new c_Cal3dB3dMesh).m_Cal3dB3dMesh_new();
			t_c3db3dm.m_MID=m_CoreModel.p_addCoreMesh(t_msh);
			print("Added: "+String(t_c3db3dm.m_MID));
			t_c3db3dm.m_CMesh=t_msh;
			t_c3db3dm.m_B3dMesh=c_TMesh.m_CreateMesh(m_B3dModel);
			t_c3db3dm.m_B3dMesh.m_anim=2;
			m_Meshes.p_AddLast9(t_c3db3dm);
		}
		return 0;
	}
	public function p_AddAnim(t_anm:c_CalCoreAnimation):int{
		if(m_Skele==null){
			return 0;
		}
		if(t_anm!=null){
			var t_aa:int=m_CoreModel.p_addCoreAnimation(t_anm);
			print("Loaded Anim: "+String(t_aa));
			m_Anims.p_AddLast10(t_anm);
		}
		return 0;
	}
	internal var m_CModel:c_CalModel=null;
	internal var m_cal_renderer:c_CalRenderer=null;
	public function p_Build():int{
		if(m_CoreModel.p_getCoreSkeleton()==null){
			print("Core Skeleton is null!");
		}
		m_CoreModel.p_getCoreSkeleton().p_calculateBoundingBoxes(m_CoreModel);
		m_CModel=m_CoreModel.p_makemodel();
		var t_:c_Enumerator13=m_Meshes.p_ObjectEnumerator();
		while(t_.p_HasNext()){
			var t_cb3d:c_Cal3dB3dMesh=t_.p_NextObject();
			m_CModel.p_attachMesh(t_cb3d.m_MID);
		}
		if(m_CModel!=null){
			print("Have Cmodel");
		}
		m_cal_renderer=m_CModel.p_getRenderer();
		m_cal_renderer.p_beginRendering();
		var t_mc:int=m_cal_renderer.p_getMeshCount();
		print("Mesh Count: "+String(t_mc));
		for(var t_i:int=0;t_i<=t_mc;t_i=t_i+1){
			var t_2:c_Enumerator13=m_Meshes.p_ObjectEnumerator();
			while(t_2.p_HasNext()){
				var t_cb3d2:c_Cal3dB3dMesh=t_2.p_NextObject();
				if(t_cb3d2.m_MID==t_i){
					print("Got Mesh: "+String(t_i));
					var t_submeshCount:int=m_cal_renderer.p_getSubmeshCount(t_i);
					print("NOF: Submeshes "+String(t_submeshCount));
					for(var t_ii:int=0;t_ii<=t_submeshCount-1;t_ii=t_ii+1){
						m_cal_renderer.p_selectMeshSubmesh(t_cb3d2.m_MID,t_ii);
						var t_vertexCount:int=m_cal_renderer.p_getVertexCount();
						var t_faceCount:int=m_cal_renderer.p_getFaceCount();
						print("Verts: "+String(t_vertexCount)+" Faces"+String(t_faceCount));
						var t_faces:Array=new_number_array(t_faceCount*3);
						var t_vertices:Array=new_number_array(t_vertexCount*3);
						m_cal_renderer.p_getVertices(t_vertices,3);
						m_cal_renderer.p_getFaces(t_faces);
						t_cb3d2.p_Build2(t_vertices,t_faces);
					}
				}
			}
		}
		m_cal_renderer.p_endRendering();
		return 0;
	}
	public function p_Update3(t_d:Number):int{
		m_CModel.p_update(t_d);
		m_cal_renderer.p_beginRendering();
		var t_mc:int=m_cal_renderer.p_getMeshCount();
		for(var t_i:int=0;t_i<=t_mc;t_i=t_i+1){
			var t_:c_Enumerator13=m_Meshes.p_ObjectEnumerator();
			while(t_.p_HasNext()){
				var t_cb3d:c_Cal3dB3dMesh=t_.p_NextObject();
				if(t_cb3d.m_MID==t_i){
					var t_submeshCount:int=m_cal_renderer.p_getSubmeshCount(t_i);
					for(var t_ii:int=0;t_ii<=t_submeshCount-1;t_ii=t_ii+1){
						m_cal_renderer.p_selectMeshSubmesh(t_cb3d.m_MID,t_ii);
						var t_vertexCount:int=m_cal_renderer.p_getVertexCount();
						var t_faceCount:int=m_cal_renderer.p_getFaceCount();
						var t_vertices:Array=new_number_array(t_vertexCount*8);
						var t_texcoords:Array=new_number_array(t_vertexCount*3);
						var t_faces:Array=new_number_array(t_faceCount*3);
						m_cal_renderer.p_getVerticesNormalsAndTexCoords(t_vertices,1);
						m_cal_renderer.p_getFaces(t_faces);
						t_cb3d.p_Update4(t_ii,t_vertices,t_faces);
					}
				}
			}
		}
		m_cal_renderer.p_endRendering();
		return 0;
	}
}
class c_Cal3dB3dMesh extends Object{
	public function m_Cal3dB3dMesh_new():c_Cal3dB3dMesh{
		return this;
	}
	internal var m_MID:int=0;
	internal var m_CMesh:c_CalCoreMesh=null;
	internal var m_B3dMesh:c_TMesh=null;
	internal var m_surf:Array=new_object_array(0);
	public function p_Build2(t_v:Array,t_f:Array):int{
		if(m_CMesh==null){
			return 0;
		}
		if(m_B3dMesh==null){
			return 0;
		}
		var t_ind:int=m_surf.length;
		m_surf=resize_object_array(m_surf,m_surf.length+1);
		m_surf[t_ind]=m_B3dMesh.p_CreateSurface(null);
		for(var t_i:int=0;t_i<=t_v.length-1;t_i=t_i+3){
			m_surf[t_ind].p_AddVertex(t_v[t_i],t_v[t_i+1],-t_v[t_i+2],0.0,0.0,0.0);
		}
		m_surf[t_ind].p_AddTriangle2(t_f,-1);
		m_surf[t_ind].p_UpdateNormals(false);
		return 0;
	}
	public function p_Update4(t_si:int,t_v:Array,t_f:Array):int{
		m_surf[t_si].p_ClearSurface(true,true,false);
		for(var t_i:int=0;t_i<=t_v.length-1;t_i=t_i+8){
			var t_vid:int=m_surf[t_si].p_AddVertex(t_v[t_i],t_v[t_i+1],-t_v[t_i+2],0.0,0.0,0.0);
			m_surf[t_si].p_VertexNormal(t_vid,t_v[t_i+3],t_v[t_i+4],-t_v[t_i+5]);
			m_surf[t_si].p_VertexTexCoords(t_vid,t_v[t_i+6],t_v[t_i+7],0.0,0);
		}
		m_surf[t_si].p_AddTriangle2(t_f,-1);
		return 0;
	}
	public function p_Update5(t_si:int,t_v:Array,t_t:Array,t_f:Array):int{
		m_surf[t_si].p_ClearSurface(true,true,false);
		for(var t_i:int=0;t_i<=t_v.length-1;t_i=t_i+3){
			var t_vid:int=m_surf[t_si].p_AddVertex(t_v[t_i],t_v[t_i+1],-t_v[t_i+2],0.0,0.0,0.0);
			m_surf[t_si].p_VertexNormal(t_vid,t_v[t_i+3],t_v[t_i+4],-t_v[t_i+5]);
		}
		m_surf[t_si].p_AddTriangle2(t_f,-1);
		return 0;
	}
}
class c_List9 extends Object{
	public function m_List_new():c_List9{
		return this;
	}
	internal var m__head:c_Node11=((new c_HeadNode9).m_HeadNode_new());
	public function p_AddLast9(t_data:c_Cal3dB3dMesh):c_Node11{
		return (new c_Node11).m_Node_new(m__head,m__head.m__pred,t_data);
	}
	public function m_List_new2(t_data:Array):c_List9{
		var t_:Array=t_data;
		var t_2:int=0;
		while(t_2<t_.length){
			var t_t:c_Cal3dB3dMesh=t_[t_2];
			t_2=t_2+1;
			this.p_AddLast9(t_t);
		}
		return this;
	}
	public function p_ObjectEnumerator():c_Enumerator13{
		return (new c_Enumerator13).m_Enumerator_new(this);
	}
}
class c_Node11 extends Object{
	internal var m__succ:c_Node11=null;
	internal var m__pred:c_Node11=null;
	internal var m__data:c_Cal3dB3dMesh=null;
	public function m_Node_new(t_succ:c_Node11,t_pred:c_Node11,t_data:c_Cal3dB3dMesh):c_Node11{
		m__succ=t_succ;
		m__pred=t_pred;
		m__succ.m__pred=this;
		m__pred.m__succ=this;
		m__data=t_data;
		return this;
	}
	public function m_Node_new2():c_Node11{
		return this;
	}
}
class c_HeadNode9 extends c_Node11{
	public function m_HeadNode_new():c_HeadNode9{
		super.m_Node_new2();
		m__succ=(this);
		m__pred=(this);
		return this;
	}
}
class c_CalCoreAnimation extends Object{
	internal var m_m_listCoreTrack:Array=[];
	public function p_getListCoreTrack():Array{
		return m_m_listCoreTrack;
	}
	internal var m_m_duration:Number=.0;
	public function p_getDuration():Number{
		return m_m_duration;
	}
	internal var m_m_listCallbacks:Array=[];
	public function p_getCallbackList():Array{
		return m_m_listCallbacks;
	}
	internal var m_m_name:String="";
	internal var m_m_filename:String="";
	public function m_CalCoreAnimation_new():c_CalCoreAnimation{
		m_m_listCallbacks=new_object_array(0);
		m_m_duration=0.0;
		m_m_listCoreTrack=new_object_array(0);
		m_m_name="Animation";
		m_m_filename="";
		return this;
	}
	public function p_setDuration(t_duration:Number):void{
		m_m_duration=t_duration;
	}
	public function p_addCoreTrack(t_coreTrack:c_CalCoreTrack):Boolean{
		m_m_listCoreTrack=resize_object_array(m_m_listCoreTrack,m_m_listCoreTrack.length+1);
		m_m_listCoreTrack[m_m_listCoreTrack.length-1]=t_coreTrack;
		return true;
	}
}
class c_List10 extends Object{
	public function m_List_new():c_List10{
		return this;
	}
	internal var m__head:c_Node12=((new c_HeadNode10).m_HeadNode_new());
	public function p_AddLast10(t_data:c_CalCoreAnimation):c_Node12{
		return (new c_Node12).m_Node_new(m__head,m__head.m__pred,t_data);
	}
	public function m_List_new2(t_data:Array):c_List10{
		var t_:Array=t_data;
		var t_2:int=0;
		while(t_2<t_.length){
			var t_t:c_CalCoreAnimation=t_[t_2];
			t_2=t_2+1;
			this.p_AddLast10(t_t);
		}
		return this;
	}
}
class c_Node12 extends Object{
	internal var m__succ:c_Node12=null;
	internal var m__pred:c_Node12=null;
	internal var m__data:c_CalCoreAnimation=null;
	public function m_Node_new(t_succ:c_Node12,t_pred:c_Node12,t_data:c_CalCoreAnimation):c_Node12{
		m__succ=t_succ;
		m__pred=t_pred;
		m__succ.m__pred=this;
		m__pred.m__succ=this;
		m__data=t_data;
		return this;
	}
	public function m_Node_new2():c_Node12{
		return this;
	}
}
class c_HeadNode10 extends c_Node12{
	public function m_HeadNode_new():c_HeadNode10{
		super.m_Node_new2();
		m__succ=(this);
		m__pred=(this);
		return this;
	}
}
class c_CalCoreModel extends Object{
	internal var m_m_name:String="";
	internal var m_m_coreSkeleton:c_CalCoreSkeleton=null;
	internal var m_m_vectorCoreAnimation:Array=[];
	internal var m_m_vectorCoreMorphAnimation:Array=[];
	internal var m_m_vectorCoreMesh:Array=[];
	internal var m_m_vectorCoreMaterial:Array=[];
	internal var m_m_mapmapCoreMaterialThread:c_IntMap3=null;
	internal var m_m_animationName:c_StringMap=null;
	internal var m_m_materialName:c_StringMap=null;
	internal var m_m_meshName:c_StringMap=null;
	public function m_CalCoreModel_new(t_name:String):c_CalCoreModel{
		m_m_name=t_name;
		m_m_coreSkeleton=null;
		m_m_vectorCoreAnimation=new_object_array(0);
		m_m_vectorCoreMorphAnimation=new_object_array(0);
		m_m_vectorCoreMesh=new_object_array(0);
		m_m_vectorCoreMaterial=new_object_array(0);
		m_m_mapmapCoreMaterialThread=(new c_IntMap3).m_IntMap_new();
		m_m_animationName=(new c_StringMap).m_StringMap_new();
		m_m_materialName=(new c_StringMap).m_StringMap_new();
		m_m_meshName=(new c_StringMap).m_StringMap_new();
		return this;
	}
	public function p_setCoreSkeleton(t_coreSkeleton:c_CalCoreSkeleton):void{
		if(t_coreSkeleton!=null){
			m_m_coreSkeleton=t_coreSkeleton;
		}else{
			print("Cannot set NULL Skeleton!");
		}
	}
	public function p_addCoreMesh(t_coreMesh:c_CalCoreMesh):int{
		var t_meshId:int=m_m_vectorCoreMesh.length;
		m_m_vectorCoreMesh=resize_object_array(m_m_vectorCoreMesh,t_meshId+1);
		m_m_vectorCoreMesh[t_meshId]=t_coreMesh;
		return t_meshId;
	}
	public function p_addCoreAnimation(t_coreAnimation:c_CalCoreAnimation):int{
		var t_animationId:int=m_m_vectorCoreAnimation.length;
		m_m_vectorCoreAnimation=resize_object_array(m_m_vectorCoreAnimation,t_animationId+1);
		m_m_vectorCoreAnimation[t_animationId]=t_coreAnimation;
		return t_animationId;
	}
	public function p_getCoreSkeleton():c_CalCoreSkeleton{
		return m_m_coreSkeleton;
	}
	public function p_getCoreMeshCount():int{
		return m_m_vectorCoreMesh.length;
	}
	public function p_getCoreMesh(t_coreMeshId:int):c_CalCoreMesh{
		if(t_coreMeshId<0 || t_coreMeshId>=m_m_vectorCoreMesh.length){
			print("Invalid Mesh ID");
			return null;
		}
		return m_m_vectorCoreMesh[t_coreMeshId];
	}
	public function p_getCoreAnimationCount():int{
		return m_m_vectorCoreAnimation.length;
	}
	public function p_getCoreMorphAnimationCount():int{
		return m_m_vectorCoreMorphAnimation.length;
	}
	public function p_makemodel():c_CalModel{
		return (new c_CalModel).m_CalModel_new2(this);
	}
	public function p_getCoreAnimation(t_coreAnimationId:int):c_CalCoreAnimation{
		if(t_coreAnimationId<0 || t_coreAnimationId>=m_m_vectorCoreAnimation.length){
			print("Invalid Animation ID");
			return null;
		}
		return m_m_vectorCoreAnimation[t_coreAnimationId];
	}
	public function p_getCoreMorphAnimation(t_coreMorphAnimationId:int):c_CalCoreMorphAnimation{
		if(t_coreMorphAnimationId<0 || t_coreMorphAnimationId>=m_m_vectorCoreMorphAnimation.length){
			print("Invalid Morph ID");
			return null;
		}
		return m_m_vectorCoreMorphAnimation[t_coreMorphAnimationId];
	}
}
class c_CalCoreSkeleton extends Object{
	internal var m_m_vectorCoreBone:Array=[];
	internal var m_m_mapCoreBoneNames:c_StringMap=null;
	public function p_getCoreBoneId(t_name:String):int{
		if(m_m_mapCoreBoneNames.p_Contains3(t_name)==true){
			return m_m_mapCoreBoneNames.p_Get2(t_name);
		}else{
			return -1;
		}
		return 0;
	}
	public function p_calculateBoundingBoxes(t_coreModel:c_CalCoreModel):void{
		for(var t_boneId:int=0;t_boneId<=m_m_vectorCoreBone.length-1;t_boneId=t_boneId+1){
			m_m_vectorCoreBone[t_boneId].p_calculateBoundingBox(t_coreModel);
		}
	}
	public function p_getVectorCoreBone():Array{
		return m_m_vectorCoreBone;
	}
	internal var m_m_vectorRootCoreBoneId:Array=[];
	public function p_getVectorRootCoreBoneId():Array{
		return m_m_vectorRootCoreBoneId;
	}
	public function m_CalCoreSkeleton_new():c_CalCoreSkeleton{
		m_m_vectorCoreBone=new_object_array(0);
		m_m_mapCoreBoneNames=(new c_StringMap).m_StringMap_new();
		m_m_vectorRootCoreBoneId=new_number_array(0);
		return this;
	}
	public function p_mapCoreBoneName(t_coreBoneId:int,t_name:String):Boolean{
		if(t_coreBoneId<0 || t_coreBoneId>=m_m_vectorCoreBone.length){
			return false;
		}
		return m_m_mapCoreBoneNames.p_Add3(t_name,t_coreBoneId);
	}
	public function p_addCoreBone(t_coreBone:c_CalCoreBone):int{
		var t_boneId:int=m_m_vectorCoreBone.length;
		m_m_vectorCoreBone=resize_object_array(m_m_vectorCoreBone,t_boneId+1);
		m_m_vectorCoreBone[t_boneId]=t_coreBone;
		if(t_coreBone.p_getParentId()==-1){
			var t_bn:int=m_m_vectorRootCoreBoneId.length;
			m_m_vectorRootCoreBoneId=resize_number_array(m_m_vectorRootCoreBoneId,t_bn+1);
			m_m_vectorRootCoreBoneId[t_bn]=t_boneId;
		}
		this.p_mapCoreBoneName(t_boneId,t_coreBone.p_getName());
		return t_boneId;
	}
	public function p_getCoreBone(t_coreBoneId:int):c_CalCoreBone{
		if(t_coreBoneId<0 || t_coreBoneId>=m_m_vectorCoreBone.length){
			print("Invalid Bone ID");
			return null;
		}
		return m_m_vectorCoreBone[t_coreBoneId];
	}
	public function p_getCoreBone2(t_coreBoneId:String):c_CalCoreBone{
		var t_bid:int=this.p_getCoreBoneId(t_coreBoneId);
		if(t_bid<0 || t_bid>=m_m_vectorCoreBone.length){
			print("Invalid Bone ID");
			return null;
		}
		return m_m_vectorCoreBone[t_bid];
	}
	public function p_calculateState():void{
		for(var t_iRootCoreBoneId:int=0;t_iRootCoreBoneId<=m_m_vectorRootCoreBoneId.length-1;t_iRootCoreBoneId=t_iRootCoreBoneId+1){
			m_m_vectorCoreBone[m_m_vectorRootCoreBoneId[t_iRootCoreBoneId]].p_calculateState();
		}
	}
}
class c_CalCoreMorphAnimation extends Object{
	internal var m_m_vectorCoreMeshID:Array=[];
	public function p_getVectorCoreMeshID():Array{
		return m_m_vectorCoreMeshID;
	}
	internal var m_m_vectorMorphTargetID:Array=[];
	public function p_getVectorMorphTargetID():Array{
		return m_m_vectorMorphTargetID;
	}
}
class c_CalCoreMesh extends Object{
	internal var m_m_vectorCoreSubmesh:Array=[];
	public function p_getCoreSubmeshCount():int{
		return m_m_vectorCoreSubmesh.length;
	}
	public function p_getCoreSubmesh(t_coreSubmeshId:int):c_CalCoreSubmesh{
		if(t_coreSubmeshId<0 || t_coreSubmeshId>=m_m_vectorCoreSubmesh.length){
			print("Invalid Submesh Handle");
			return null;
		}
		return m_m_vectorCoreSubmesh[t_coreSubmeshId];
	}
	public function p_getVectorCoreSubmesh():Array{
		return m_m_vectorCoreSubmesh;
	}
	public function m_CalCoreMesh_new():c_CalCoreMesh{
		m_m_vectorCoreSubmesh=new_object_array(0);
		return this;
	}
	public function p_addCoreSubmesh(t_coreSubmesh:c_CalCoreSubmesh):int{
		var t_submeshId:int=m_m_vectorCoreSubmesh.length;
		m_m_vectorCoreSubmesh=resize_object_array(m_m_vectorCoreSubmesh,t_submeshId+1);
		m_m_vectorCoreSubmesh[t_submeshId]=t_coreSubmesh;
		return t_submeshId;
	}
}
class c_CalCoreMaterial extends Object{
}
class c_Map2 extends Object{
}
class c_IntMap2 extends c_Map2{
}
class c_Map3 extends Object{
	public function m_Map_new():c_Map3{
		return this;
	}
}
class c_IntMap3 extends c_Map3{
	public function m_IntMap_new():c_IntMap3{
		super.m_Map_new();
		return this;
	}
}
class c_Map4 extends Object{
	public function m_Map_new():c_Map4{
		return this;
	}
	internal var m_root:c_Node14=null;
	public function p_Compare3(t_lhs:String,t_rhs:String):int{
		return 0;
	}
	public function p_FindNode2(t_key:String):c_Node14{
		var t_node:c_Node14=m_root;
		while((t_node)!=null){
			var t_cmp:int=this.p_Compare3(t_key,t_node.m_key);
			if(t_cmp>0){
				t_node=t_node.m_right;
			}else{
				if(t_cmp<0){
					t_node=t_node.m_left;
				}else{
					return t_node;
				}
			}
		}
		return t_node;
	}
	public function p_Contains3(t_key:String):Boolean{
		return this.p_FindNode2(t_key)!=null;
	}
	public function p_Get2(t_key:String):int{
		var t_node:c_Node14=this.p_FindNode2(t_key);
		if((t_node)!=null){
			return t_node.m_value;
		}
		return 0;
	}
	public function p_RotateLeft2(t_node:c_Node14):int{
		var t_child:c_Node14=t_node.m_right;
		t_node.m_right=t_child.m_left;
		if((t_child.m_left)!=null){
			t_child.m_left.m_parent=t_node;
		}
		t_child.m_parent=t_node.m_parent;
		if((t_node.m_parent)!=null){
			if(t_node==t_node.m_parent.m_left){
				t_node.m_parent.m_left=t_child;
			}else{
				t_node.m_parent.m_right=t_child;
			}
		}else{
			m_root=t_child;
		}
		t_child.m_left=t_node;
		t_node.m_parent=t_child;
		return 0;
	}
	public function p_RotateRight2(t_node:c_Node14):int{
		var t_child:c_Node14=t_node.m_left;
		t_node.m_left=t_child.m_right;
		if((t_child.m_right)!=null){
			t_child.m_right.m_parent=t_node;
		}
		t_child.m_parent=t_node.m_parent;
		if((t_node.m_parent)!=null){
			if(t_node==t_node.m_parent.m_right){
				t_node.m_parent.m_right=t_child;
			}else{
				t_node.m_parent.m_left=t_child;
			}
		}else{
			m_root=t_child;
		}
		t_child.m_right=t_node;
		t_node.m_parent=t_child;
		return 0;
	}
	public function p_InsertFixup2(t_node:c_Node14):int{
		while(((t_node.m_parent)!=null) && t_node.m_parent.m_color==-1 && ((t_node.m_parent.m_parent)!=null)){
			if(t_node.m_parent==t_node.m_parent.m_parent.m_left){
				var t_uncle:c_Node14=t_node.m_parent.m_parent.m_right;
				if(((t_uncle)!=null) && t_uncle.m_color==-1){
					t_node.m_parent.m_color=1;
					t_uncle.m_color=1;
					t_uncle.m_parent.m_color=-1;
					t_node=t_uncle.m_parent;
				}else{
					if(t_node==t_node.m_parent.m_right){
						t_node=t_node.m_parent;
						this.p_RotateLeft2(t_node);
					}
					t_node.m_parent.m_color=1;
					t_node.m_parent.m_parent.m_color=-1;
					this.p_RotateRight2(t_node.m_parent.m_parent);
				}
			}else{
				var t_uncle2:c_Node14=t_node.m_parent.m_parent.m_left;
				if(((t_uncle2)!=null) && t_uncle2.m_color==-1){
					t_node.m_parent.m_color=1;
					t_uncle2.m_color=1;
					t_uncle2.m_parent.m_color=-1;
					t_node=t_uncle2.m_parent;
				}else{
					if(t_node==t_node.m_parent.m_left){
						t_node=t_node.m_parent;
						this.p_RotateRight2(t_node);
					}
					t_node.m_parent.m_color=1;
					t_node.m_parent.m_parent.m_color=-1;
					this.p_RotateLeft2(t_node.m_parent.m_parent);
				}
			}
		}
		m_root.m_color=1;
		return 0;
	}
	public function p_Add3(t_key:String,t_value:int):Boolean{
		var t_node:c_Node14=m_root;
		var t_parent:c_Node14=null;
		var t_cmp:int=0;
		while((t_node)!=null){
			t_parent=t_node;
			t_cmp=this.p_Compare3(t_key,t_node.m_key);
			if(t_cmp>0){
				t_node=t_node.m_right;
			}else{
				if(t_cmp<0){
					t_node=t_node.m_left;
				}else{
					return false;
				}
			}
		}
		t_node=(new c_Node14).m_Node_new(t_key,t_value,-1,t_parent);
		if((t_parent)!=null){
			if(t_cmp>0){
				t_parent.m_right=t_node;
			}else{
				t_parent.m_left=t_node;
			}
			this.p_InsertFixup2(t_node);
		}else{
			m_root=t_node;
		}
		return true;
	}
}
class c_StringMap extends c_Map4{
	public function m_StringMap_new():c_StringMap{
		super.m_Map_new();
		return this;
	}
	public override function p_Compare3(t_lhs:String,t_rhs:String):int{
		return string_compare(t_lhs,t_rhs);
	}
}
class c_DeltaTimer extends Object{
	internal var m_targetfps:Number=60.0;
	internal var m_lastticks:Number=.0;
	public function m_DeltaTimer_new(t_fps:Number):c_DeltaTimer{
		m_targetfps=t_fps;
		m_lastticks=(bb_app2_Millisecs());
		return this;
	}
	public function m_DeltaTimer_new2():c_DeltaTimer{
		return this;
	}
	internal var m_delta:Number=.0;
	internal var m_currentticks:Number=.0;
	internal var m_frametime:Number=.0;
	public function p_UpdateDelta():void{
		m_currentticks=(bb_app2_Millisecs());
		m_frametime=m_currentticks-m_lastticks;
		m_delta=m_frametime/(1000.0/m_targetfps);
		m_lastticks=m_currentticks;
	}
}
internal function bb_functions_CreateCamera(t_parent:c_TEntity):c_TCamera{
	return c_TCamera.m_CreateCamera(t_parent);
}
class c_TBone extends c_TEntity{
	internal var m_rest_mat:c_Matrix=(new c_Matrix).m_Matrix_new();
	internal static var m_t_mat:c_Matrix;
	internal var m_mat2:c_Matrix=(new c_Matrix).m_Matrix_new();
	internal static var m_new_mat:c_Matrix;
	internal var m_tform_mat:c_Matrix=(new c_Matrix).m_Matrix_new();
	internal var m_inv_mat:c_Matrix=(new c_Matrix).m_Matrix_new();
	public function p_UpdateMatrix(t_mat0:c_Matrix):void{
		m_loc_mat.p_Overwrite(t_mat0);
		m_mat2.p_Overwrite(m_loc_mat);
		if(m_parent!=null){
			m_mat.p_Overwrite(m_parent.m_mat);
			m_mat.p_Multiply(m_loc_mat);
			m_gsx=m_parent.m_gsx*m_sx;
			m_gsy=m_parent.m_gsy*m_sy;
			m_gsz=m_parent.m_gsz*m_sz;
		}
		if(((this.m_parent) as c_TBone)!=null){
			m_new_mat.p_Overwrite(((m_parent) as c_TBone).m_mat2);
			m_new_mat.p_Multiply(m_loc_mat);
			m_mat2.p_Overwrite(m_new_mat);
		}
		m_tform_mat.p_Overwrite(m_mat2);
		m_tform_mat.p_Multiply(m_inv_mat);
	}
	public static function m_UpdateNonBoneChild(t_ent_p:c_TEntity):void{
		if(((t_ent_p) as c_TBone)==null){
			m_new_mat.p_Overwrite(t_ent_p.m_parent.m_mat);
			if(((t_ent_p) as c_TBone)!=null){
				m_new_mat.m_grid[3][2]=-m_new_mat.m_grid[3][2];
			}
			t_ent_p.m_mat.p_Overwrite(m_new_mat);
			t_ent_p.p_UpdateMat(false);
		}
	}
	public static function m_UpdateBoneChildren(t_p:c_TEntity):void{
		var t_:c_Enumerator7=t_p.m_child_list.p_ObjectEnumerator();
		while(t_.p_HasNext()){
			var t_ent:c_TEntity=t_.p_NextObject();
			var t_bo:c_TBone=((t_ent) as c_TBone);
			if(t_bo!=null){
				t_bo.p_UpdateMatrix(t_bo.m_loc_mat);
			}else{
				m_UpdateNonBoneChild(t_ent);
			}
			m_UpdateBoneChildren(t_ent);
		}
	}
	public function p_PositionBone(t_x:Number,t_y:Number,t_z:Number,t_glob:int):int{
		m_px=t_x;
		m_py=t_y;
		m_pz=t_z;
		m_t_mat.p_Overwrite(m_rest_mat);
		m_t_mat.p_Multiply(m_loc_mat);
		m_t_mat.m_grid[3][0]=t_x+m_rest_mat.m_grid[3][0];
		m_t_mat.m_grid[3][1]=t_y+m_rest_mat.m_grid[3][1];
		m_t_mat.m_grid[3][2]=t_z+m_rest_mat.m_grid[3][2];
		this.p_UpdateMatrix(m_t_mat);
		if(this.m_child_list.p_IsEmpty()!=true){
			m_UpdateBoneChildren(this);
		}
		return 0;
	}
	public function p_RotateBone(t_x:Number,t_y:Number,t_z:Number,t_glob:int):int{
		m_rx=-t_x;
		m_ry=t_y;
		m_rz=t_z;
		m_t_mat.p_Overwrite(m_rest_mat);
		m_t_mat.m_grid[3][0]=m_px+m_rest_mat.m_grid[3][0];
		m_t_mat.m_grid[3][1]=m_py+m_rest_mat.m_grid[3][1];
		m_t_mat.m_grid[3][2]=m_pz+m_rest_mat.m_grid[3][2];
		m_t_mat.p_Rotate(t_x,t_y,t_z);
		this.p_UpdateMatrix(m_t_mat);
		if(this.m_child_list.p_IsEmpty()!=true){
			m_UpdateBoneChildren(this);
		}
		return 0;
	}
	public function p_ScaleBone(t_x:Number,t_y:Number,t_z:Number,t_glob:int):int{
		m_sx=t_x;
		m_sy=t_y;
		m_sz=t_z;
		m_t_mat.p_Overwrite(m_rest_mat);
		m_t_mat.m_grid[3][0]=m_px+m_rest_mat.m_grid[3][0];
		m_t_mat.m_grid[3][1]=m_py+m_rest_mat.m_grid[3][1];
		m_t_mat.m_grid[3][2]=m_pz+m_rest_mat.m_grid[3][2];
		m_t_mat.p_Rotate(m_rx,m_ry,m_rz);
		m_t_mat.p_Scale(t_x,t_y,t_z);
		this.p_UpdateMatrix(m_t_mat);
		m_gsx=m_parent.m_gsx*m_sx;
		m_gsy=m_parent.m_gsy*m_sy;
		m_gsz=m_parent.m_gsz*m_sz;
		if(this.m_child_list.p_IsEmpty()!=true){
			m_UpdateBoneChildren(this);
		}
		return 0;
	}
}
class c_Line extends Object{
	internal var m_o:c_Vector=null;
	internal var m_d:c_Vector=null;
	public function m_Line_new():c_Line{
		m_o=(new c_Vector).m_Vector_new(0.0,0.0,0.0);
		m_d=(new c_Vector).m_Vector_new(0.0,0.0,0.0);
		return this;
	}
	public function m_Line_new2(t_oo:c_Vector,t_dd:c_Vector):c_Line{
		m_o=t_oo.p_Copy();
		m_d=t_dd.p_Copy();
		return this;
	}
	public function m_Line_new3(t_ox:Number,t_oy:Number,t_oz:Number,t_dx:Number,t_dy:Number,t_dz:Number):c_Line{
		m_o=(new c_Vector).m_Vector_new(t_ox,t_oy,t_oz);
		m_d=(new c_Vector).m_Vector_new(t_dx,t_dy,t_dz);
		return this;
	}
}
internal function bb_functions_CreateLight(t_light_type:int,t_parent:c_TEntity):c_TLight{
	return c_TLight.m_CreateLight(t_light_type,t_parent);
}
internal function bb_functions_CreateCube(t_parent:c_TEntity):c_TMesh{
	return c_TMesh.m_CreateCube(t_parent);
}
class c_TText extends c_TSprite{
	public function m_TText_new():c_TText{
		super.m_TSprite_new();
		return this;
	}
	internal var m_text:String="";
	internal var m_length:int=0;
	internal var m_cam:c_TCamera=null;
	internal var m_char_pixels:Number=.0;
	internal var m_font_file:String="";
	internal var m_orig_width:Number=.0;
	internal var m_orig_height:Number=.0;
	internal static var m_mask_color:int;
	internal var m_surf:c_TSurface=null;
	internal var m_char_rows:int=0;
	internal var m_pixel_ratio:Number=.0;
	internal var m_char_uvwidth:Number=.0;
	internal var m_padding:int=0;
	internal var m_mode:Boolean=true;
	internal var m_old_text:String="";
	public function p_AddChar(t_char:int,t_num:int,t_x:Number,t_y:Number,t_offset:Number):int{
		var t_uv:Number=((t_char)-32.0)*m_char_uvwidth+((t_char)-32.0)*(m_padding);
		var t_uv2:Number=0.9999;
		if(t_char==32){
			t_uv=0.0;
			t_uv2=0.0001;
		}
		if(t_uv<0.0){
			t_uv=0.0;
			t_uv2=0.0001;
		}
		var t_kern:Number=0.3*t_x+t_offset;
		m_surf.p_AddVertex(0.0+t_x-t_kern,0.0+t_y,0.0,t_uv,t_uv2,0.0);
		m_surf.p_AddVertex(0.0+t_x-t_kern,1.0+t_y,0.0,t_uv,0.0001,0.0);
		m_surf.p_AddVertex(1.0+t_x-t_kern,1.0+t_y,0.0,t_uv+m_char_uvwidth,0.0001,0.0);
		m_surf.p_AddVertex(1.0+t_x-t_kern,0.0+t_y,0.0,t_uv+m_char_uvwidth,t_uv2,0.0);
		var t_v:int=t_num*4;
		m_surf.p_AddTriangle(0+t_v,1+t_v,2+t_v);
		m_surf.p_AddTriangle(0+t_v,2+t_v,3+t_v);
		return 0;
	}
	public function p_AdjustChar(t_char:int,t_num:int,t_x:Number,t_y:Number):int{
		var t_uv:Number=((t_char)-32.0)*m_char_uvwidth+((t_char)-32.0)*(m_padding);
		var t_uv2:Number=0.9999;
		if(t_char==32){
			t_uv=0.0;
			t_uv2=0.0001;
		}
		if(t_uv<0.0){
			t_uv=0.0;
			t_uv2=0.0001;
		}
		var t_kern:Number=0.3*t_x;
		var t_v:int=t_num*4;
		m_surf.p_VertexTexCoords(t_v+0,t_uv,t_uv2,0.0,0);
		m_surf.p_VertexTexCoords(t_v+1,t_uv,0.0001,0.0,0);
		m_surf.p_VertexTexCoords(t_v+2,t_uv+m_char_uvwidth,0.0001,0.0,0);
		m_surf.p_VertexTexCoords(t_v+3,t_uv+m_char_uvwidth,t_uv2,0.0,0);
		return 0;
	}
	public function p_SetText(t_str:String,t_x:Number,t_y:Number,t_z:Number,t_align:int):int{
		var t_resurf:int=0;
		if(m_mode==false){
			this.p_PositionEntity(t_x,t_y,t_z,0);
		}
		if(t_str==m_old_text || t_str==""){
			return 0;
		}
		if(t_str.length!=m_old_text.length){
			if((m_surf)!=null){
				m_surf.p_ClearSurface(true,true,false);
			}else{
				m_surf=this.p_CreateSurface(null);
			}
			t_resurf=1;
		}
		m_old_text=t_str;
		var t_nl:int=-1;
		var t_xx:int=0;
		var t_total:int=0;
		var t_offset:Number=0.0;
		if(t_align==1){
			t_offset=(t_str.length)*0.15;
		}
		for(var t_i:int=0;t_i<=t_str.length-1;t_i=t_i+1){
			if(t_str.charCodeAt(t_i)==13 || t_str.charCodeAt(t_i)==10){
				t_nl=t_nl-1;
				t_xx=0;
				continue;
			}
			if((t_resurf)!=0){
				this.p_AddChar(t_str.charCodeAt(t_i),t_total,(t_xx),(t_nl),t_offset);
			}else{
				this.p_AdjustChar(t_str.charCodeAt(t_i),t_total,(t_xx),(t_nl));
			}
			t_xx+=1;
			t_total+=1;
		}
		if((t_resurf)!=0){
			m_surf.p_CropSurfaceBuffers();
		}
		return 0;
	}
	public static function m_CreateText(t_camx:c_TCamera,t_str:String,t_font:String,t_num_chars:int,t_c_pixels:int,t_pad:Number,t_mode:Boolean):c_TText{
		var t_tt:c_TText=(new c_TText).m_TText_new();
		t_tt.m_entity_link=c_TEntity.m_entity_list.p_EntityListAdd(t_tt);
		t_tt.m_text=t_str;
		t_tt.m_length=t_str.length;
		t_tt.m_cam=t_camx;
		t_tt.m_classname="TextSprite";
		t_tt.m_is_sprite=true;
		t_tt.m_char_pixels=(t_c_pixels);
		if(t_font!=""){
			t_tt.m_font_file=t_font;
		}else{
			t_tt.m_font_file="mojo_font.png";
		}
		c_TTexture.m_useGlobalResizeSmooth=false;
		var t_pixmap:c_TPixmap=c_TPixmap.m_LoadPixmap(t_tt.m_font_file).p_Copy();
		t_tt.m_orig_width=(t_pixmap.m_width);
		t_tt.m_orig_height=(t_pixmap.m_height);
		if(t_pixmap.m_height==0){
			print("Font file not found.");
			return t_tt;
		}
		t_pixmap.p_MaskPixmap(m_mask_color&255,(m_mask_color&65280)>>8,(m_mask_color&16711680)>>16);
		var t_tex:c_TTexture=c_TTexture.m_LoadTexture2(t_pixmap,3,null);
		c_TTexture.m_useGlobalResizeSmooth=true;
		t_tex.m_is_font=true;
		t_tex.m_flags=50;
		t_tex.p_TextureBlend(2);
		t_tt.p_EntityShininess(0.0);
		t_tt.m_surf=t_tt.p_CreateSurface(null);
		t_tt.p_EntityTexture(t_tex,0,0);
		t_tt.m_char_rows=((Math.ceil(((t_c_pixels*t_num_chars)+(t_num_chars)*(t_pad*2.0))/t_tt.m_orig_width))|0);
		t_tt.m_pixel_ratio=(t_tex.m_width)/t_tt.m_orig_width;
		var t_temp_chars_per_row:int=((Math.floor((t_num_chars/t_tt.m_char_rows)|0))|0);
		t_tt.m_char_uvwidth=t_tt.m_char_pixels*t_tt.m_pixel_ratio/(t_tex.m_width);
		t_tt.m_padding=((t_tt.m_pixel_ratio*t_pad)|0);
		if(t_tt.m_parent!=null){
			t_tt.m_mat.p_Overwrite(t_tt.m_parent.m_mat);
			t_tt.p_UpdateMat(false);
		}else{
			t_tt.p_UpdateMat(true);
		}
		t_tt.p_EntityFX(33);
		t_tt.p_SetText(t_str,0.0,0.0,0.0,0);
		return t_tt;
	}
	public static function m_CreateText2D(t_camx:c_TCamera,t_str:String,t_font:String,t_num_chars:int,t_c_pixels:int,t_pad:int):c_TText{
		var t_tt:c_TText=m_CreateText(t_camx,t_str,t_font,t_num_chars,t_c_pixels,(t_pad),true);
		t_tt.p_HideEntity();
		return t_tt;
	}
}
interface c_IPixmapManager{
	function p_LoadPixmap(t_f:String):c_TPixmap;
	function p_CreatePixmap(t_w:int,t_h:int,t_format:int):c_TPixmap;
}
class c_TTextureFilter extends Object{
	internal static var m_filter_list:c_List11;
	internal var m_text:String="";
	internal var m_flags:int=0;
	public function m_TTextureFilter_new():c_TTextureFilter{
		return this;
	}
}
class c_List11 extends Object{
	public function m_List_new():c_List11{
		return this;
	}
	internal var m__head:c_Node13=((new c_HeadNode11).m_HeadNode_new());
	public function p_AddLast11(t_data:c_TTextureFilter):c_Node13{
		return (new c_Node13).m_Node_new(m__head,m__head.m__pred,t_data);
	}
	public function m_List_new2(t_data:Array):c_List11{
		var t_:Array=t_data;
		var t_2:int=0;
		while(t_2<t_.length){
			var t_t:c_TTextureFilter=t_[t_2];
			t_2=t_2+1;
			this.p_AddLast11(t_t);
		}
		return this;
	}
	public function p_ObjectEnumerator():c_Enumerator10{
		return (new c_Enumerator10).m_Enumerator_new(this);
	}
}
class c_Node13 extends Object{
	internal var m__succ:c_Node13=null;
	internal var m__pred:c_Node13=null;
	internal var m__data:c_TTextureFilter=null;
	public function m_Node_new(t_succ:c_Node13,t_pred:c_Node13,t_data:c_TTextureFilter):c_Node13{
		m__succ=t_succ;
		m__pred=t_pred;
		m__succ.m__pred=this;
		m__pred.m__succ=this;
		m__data=t_data;
		return this;
	}
	public function m_Node_new2():c_Node13{
		return this;
	}
}
class c_HeadNode11 extends c_Node13{
	public function m_HeadNode_new():c_HeadNode11{
		super.m_Node_new2();
		m__succ=(this);
		m__pred=(this);
		return this;
	}
}
class c_Enumerator10 extends Object{
	internal var m__list:c_List11=null;
	internal var m__curr:c_Node13=null;
	public function m_Enumerator_new(t_list:c_List11):c_Enumerator10{
		m__list=t_list;
		m__curr=t_list.m__head.m__succ;
		return this;
	}
	public function m_Enumerator_new2():c_Enumerator10{
		return this;
	}
	public function p_HasNext():Boolean{
		while(m__curr.m__succ.m__pred!=m__curr){
			m__curr=m__curr.m__succ;
		}
		return m__curr!=m__list.m__head;
	}
	public function p_NextObject():c_TTextureFilter{
		var t_data:c_TTextureFilter=m__curr.m__data;
		m__curr=m__curr.m__succ;
		return t_data;
	}
}
class c_List12 extends Object{
	public function m_List_new():c_List12{
		return this;
	}
	internal var m__head:c_Node6=((new c_HeadNode12).m_HeadNode_new());
	public function p_AddLast12(t_data:c_TTexture):c_Node6{
		return (new c_Node6).m_Node_new(m__head,m__head.m__pred,t_data);
	}
	public function m_List_new2(t_data:Array):c_List12{
		var t_:Array=t_data;
		var t_2:int=0;
		while(t_2<t_.length){
			var t_t:c_TTexture=t_[t_2];
			t_2=t_2+1;
			this.p_AddLast12(t_t);
		}
		return this;
	}
	public function p_ObjectEnumerator():c_Enumerator11{
		return (new c_Enumerator11).m_Enumerator_new(this);
	}
}
class c_HeadNode12 extends c_Node6{
	public function m_HeadNode_new():c_HeadNode12{
		super.m_Node_new2();
		m__succ=(this);
		m__pred=(this);
		return this;
	}
}
class c_Enumerator11 extends Object{
	internal var m__list:c_List12=null;
	internal var m__curr:c_Node6=null;
	public function m_Enumerator_new(t_list:c_List12):c_Enumerator11{
		m__list=t_list;
		m__curr=t_list.m__head.m__succ;
		return this;
	}
	public function m_Enumerator_new2():c_Enumerator11{
		return this;
	}
	public function p_HasNext():Boolean{
		while(m__curr.m__succ.m__pred!=m__curr){
			m__curr=m__curr.m__succ;
		}
		return m__curr!=m__list.m__head;
	}
	public function p_NextObject():c_TTexture{
		var t_data:c_TTexture=m__curr.m__data;
		m__curr=m__curr.m__succ;
		return t_data;
	}
}
internal function bb_input_KeyHit(t_key:int):int{
	return bb_input_device.p_KeyHit(t_key);
}
class c_Enumerator12 extends Object{
	internal var m__list:c_List8=null;
	internal var m__curr:c_Node10=null;
	public function m_Enumerator_new(t_list:c_List8):c_Enumerator12{
		m__list=t_list;
		m__curr=t_list.m__head.m__succ;
		return this;
	}
	public function m_Enumerator_new2():c_Enumerator12{
		return this;
	}
	public function p_HasNext():Boolean{
		while(m__curr.m__succ.m__pred!=m__curr){
			m__curr=m__curr.m__succ;
		}
		return m__curr!=m__list.m__head;
	}
	public function p_NextObject():c_CalLoadingCallback{
		var t_data:c_CalLoadingCallback=m__curr.m__data;
		m__curr=m__curr.m__succ;
		return t_data;
	}
}
class c_CalCoreBone extends Object{
	internal var m_m_name:String="";
	internal var m_m_coreSkeleton:c_CalCoreSkeleton=null;
	internal var m_m_rotationBoneSpace:c_CalQuaternion=null;
	internal var m_m_boundingBox:c_CalBoundingBox=null;
	internal var m_m_boundingPosition:Array=[];
	internal var m_m_translation:c_CalVector=null;
	internal var m_m_boundingBoxPrecomputed:Boolean=false;
	public function p_calculateBoundingBox(t_coreModel:c_CalCoreModel):void{
		var t_boneId:int=m_m_coreSkeleton.p_getCoreBoneId(m_m_name);
		var t_bBoundsComputed:Boolean=false;
		var t_rot:c_CalQuaternion=(new c_CalQuaternion).m_CalQuaternion_new2(m_m_rotationBoneSpace);
		t_rot.p_invert();
		var t_dir:c_CalVector=(new c_CalVector).m_CalVector_new3(1.0,0.0,0.0);
		t_dir.p_multQuaternionLocal(t_rot);
		m_m_boundingBox.m_plane[0].p_setNormal(t_dir);
		t_dir.p_assign3(-1.0,0.0,0.0);
		t_dir.p_multQuaternionLocal(t_rot);
		m_m_boundingBox.m_plane[1].p_setNormal(t_dir);
		t_dir.p_assign3(0.0,1.0,0.0);
		t_dir.p_multQuaternionLocal(t_rot);
		m_m_boundingBox.m_plane[2].p_setNormal(t_dir);
		t_dir.p_assign3(0.0,-1.0,0.0);
		t_dir.p_multQuaternionLocal(t_rot);
		m_m_boundingBox.m_plane[3].p_setNormal(t_dir);
		t_dir.p_assign3(0.0,0.0,1.0);
		t_dir.p_multQuaternionLocal(t_rot);
		m_m_boundingBox.m_plane[4].p_setNormal(t_dir);
		t_dir.p_assign3(0.0,0.0,-1.0);
		t_dir.p_multQuaternionLocal(t_rot);
		m_m_boundingBox.m_plane[5].p_setNormal(t_dir);
		var t_coreMeshCount:int=t_coreModel.p_getCoreMeshCount();
		for(var t_meshId:int=0;t_meshId<=t_coreMeshCount-1;t_meshId=t_meshId+1){
			var t_coreMesh:c_CalCoreMesh=t_coreModel.p_getCoreMesh(t_meshId);
			var t_coreSubmeshCount:int=t_coreMesh.p_getCoreSubmeshCount();
			for(var t_submeshId:int=0;t_submeshId<=t_coreSubmeshCount-1;t_submeshId=t_submeshId+1){
				var t_coreSubmesh:c_CalCoreSubmesh=t_coreMesh.p_getCoreSubmesh(t_submeshId);
				if(t_coreSubmesh.p_getSpringCount()==0){
					var t_vectorVertex:Array=t_coreSubmesh.p_getVectorVertex();
					for(var t_vertexId:int=0;t_vertexId<=t_vectorVertex.length-1;t_vertexId=t_vertexId+1){
						var t_vertexInfluenceCount:int=t_vectorVertex[t_vertexId].m_vectorInfluence.length;
						for(var t_influenceId:int=0;t_influenceId<=t_vertexInfluenceCount-1;t_influenceId=t_influenceId+1){
							if(t_vectorVertex[t_vertexId].m_vectorInfluence[t_influenceId].m_boneId==t_boneId && t_vectorVertex[t_vertexId].m_vectorInfluence[t_influenceId].m_weight>0.5){
								for(var t_planeId:int=0;t_planeId<=5;t_planeId=t_planeId+1){
									if(m_m_boundingBox.m_plane[t_planeId].p_eval(t_vectorVertex[t_vertexId].m_position)<0.0){
										m_m_boundingBox.m_plane[t_planeId].p_setPosition(t_vectorVertex[t_vertexId].m_position);
										m_m_boundingPosition[t_planeId].p_assign4(t_vectorVertex[t_vertexId].m_position);
										t_bBoundsComputed=true;
									}
								}
							}
						}
					}
				}
			}
		}
		if(t_bBoundsComputed==false){
			for(var t_planeId2:int=0;t_planeId2<=5;t_planeId2=t_planeId2+1){
				m_m_boundingBox.m_plane[t_planeId2].p_setPosition(m_m_translation);
				m_m_boundingPosition[t_planeId2].p_assign4(m_m_translation);
			}
		}
		m_m_boundingBoxPrecomputed=true;
	}
	public function p_getTranslation():c_CalVector{
		return m_m_translation;
	}
	internal var m_m_rotation:c_CalQuaternion=null;
	public function p_getRotation():c_CalQuaternion{
		return m_m_rotation;
	}
	internal var m_m_parentId:int=0;
	public function p_getParentId():int{
		return m_m_parentId;
	}
	internal var m_m_translationBoneSpace:c_CalVector=null;
	public function p_getTranslationBoneSpace():c_CalVector{
		return m_m_translationBoneSpace;
	}
	public function p_getRotationBoneSpace():c_CalQuaternion{
		return m_m_rotationBoneSpace;
	}
	internal var m_m_listChildId:Array=[];
	public function p_getListChildId():Array{
		return m_m_listChildId;
	}
	internal var m_m_translationAbsolute:c_CalVector=null;
	internal var m_m_rotationAbsolute:c_CalQuaternion=null;
	internal var m_m_userData:Object=null;
	public function m_CalCoreBone_new(t_name:String):c_CalCoreBone{
		m_m_name=t_name;
		m_m_coreSkeleton=null;
		m_m_parentId=-1;
		m_m_listChildId=new_number_array(0);
		m_m_translation=(new c_CalVector).m_CalVector_new();
		m_m_rotation=(new c_CalQuaternion).m_CalQuaternion_new();
		m_m_translationAbsolute=(new c_CalVector).m_CalVector_new();
		m_m_rotationAbsolute=(new c_CalQuaternion).m_CalQuaternion_new();
		m_m_translationBoneSpace=(new c_CalVector).m_CalVector_new();
		m_m_rotationBoneSpace=(new c_CalQuaternion).m_CalQuaternion_new();
		m_m_userData=null;
		m_m_boundingBox=(new c_CalBoundingBox).m_CalBoundingBox_new();
		m_m_boundingPosition=new_object_array(6);
		for(var t_i:int=0;t_i<=5;t_i=t_i+1){
			m_m_boundingPosition[t_i]=(new c_CalVector).m_CalVector_new();
		}
		m_m_boundingBoxPrecomputed=false;
		return this;
	}
	public function p_setParentId(t_parentId:int):void{
		m_m_parentId=t_parentId;
	}
	public function p_setTranslation(t_translation:c_CalVector):void{
		m_m_translation.p_assign4(t_translation);
	}
	public function p_setRotation(t_rotation:c_CalQuaternion):void{
		m_m_rotation.p_assign(t_rotation);
	}
	public function p_setTranslationBoneSpace(t_translation:c_CalVector):void{
		m_m_translationBoneSpace.p_assign4(t_translation);
	}
	public function p_setRotationBoneSpace(t_rotation:c_CalQuaternion):void{
		m_m_rotationBoneSpace.p_assign(t_rotation);
	}
	public function p_addChildId(t_childId:int):Boolean{
		var t_id:int=m_m_listChildId.length;
		m_m_listChildId=resize_number_array(m_m_listChildId,m_m_listChildId.length+1);
		m_m_listChildId[t_id]=t_childId;
		return true;
	}
	public function p_setCoreSkeleton(t_coreSkeleton:c_CalCoreSkeleton):void{
		m_m_coreSkeleton=t_coreSkeleton;
	}
	public function p_getName():String{
		return m_m_name;
	}
	public function p_getRotationAbsolute():c_CalQuaternion{
		return m_m_rotationAbsolute;
	}
	public function p_getTranslationAbsolute():c_CalVector{
		return m_m_translationAbsolute;
	}
	public function p_calculateState():void{
		if(m_m_parentId==-1){
			m_m_translationAbsolute.p_assign4(m_m_translation);
			m_m_rotationAbsolute.p_assign(m_m_rotation);
		}else{
			var t_parent:c_CalCoreBone=m_m_coreSkeleton.p_getCoreBone(m_m_parentId);
			m_m_translationAbsolute.p_assign4(m_m_translation);
			m_m_translationAbsolute.p_multQuaternionLocal(t_parent.p_getRotationAbsolute());
			m_m_translationAbsolute.p_addLocal(t_parent.p_getTranslationAbsolute());
			m_m_rotationAbsolute.p_assign(m_m_rotation);
			m_m_rotationAbsolute.p_multQuaternionLocal(t_parent.p_getRotationAbsolute());
		}
		for(var t_iChildId:int=0;t_iChildId<=m_m_listChildId.length-1;t_iChildId=t_iChildId+1){
			m_m_coreSkeleton.p_getCoreBone(m_m_listChildId[t_iChildId]).p_calculateState();
		}
	}
}
class c_Node14 extends Object{
	internal var m_key:String="";
	internal var m_right:c_Node14=null;
	internal var m_left:c_Node14=null;
	internal var m_value:int=0;
	internal var m_color:int=0;
	internal var m_parent:c_Node14=null;
	public function m_Node_new(t_key:String,t_value:int,t_color:int,t_parent:c_Node14):c_Node14{
		this.m_key=t_key;
		this.m_value=t_value;
		this.m_color=t_color;
		this.m_parent=t_parent;
		return this;
	}
	public function m_Node_new2():c_Node14{
		return this;
	}
}
class c_CalQuaternion extends Object{
	internal var m_x:Number=.0;
	internal var m_y:Number=.0;
	internal var m_z:Number=.0;
	internal var m_w:Number=.0;
	public function m_CalQuaternion_new():c_CalQuaternion{
		m_x=0.0;
		m_y=0.0;
		m_z=0.0;
		m_w=1.0;
		return this;
	}
	public function m_CalQuaternion_new2(t_other:c_CalQuaternion):c_CalQuaternion{
		m_x=t_other.m_x;
		m_y=t_other.m_y;
		m_z=t_other.m_z;
		m_w=t_other.m_w;
		return this;
	}
	public function m_CalQuaternion_new3(t_xx:Number,t_yy:Number,t_zz:Number,t_ww:Number):c_CalQuaternion{
		m_x=t_xx;
		m_y=t_yy;
		m_z=t_zz;
		m_w=t_ww;
		return this;
	}
	public function p_conjugate():void{
		m_x=-m_x;
		m_y=-m_y;
		m_z=-m_z;
	}
	public function p_invert():void{
		this.p_conjugate();
		var t_norm:Number=m_x*m_x+m_y*m_y+m_z*m_z+m_w*m_w;
		if(t_norm==0.0){
			return;
		}
		var t_inv_norm:Number=1.0/t_norm;
		m_x*=t_inv_norm;
		m_y*=t_inv_norm;
		m_z*=t_inv_norm;
		m_w*=t_inv_norm;
	}
	public function p_multVectorLocal(t_v:c_CalVector):c_CalQuaternion{
		var t_qx:Number=m_x;
		var t_qy:Number=m_y;
		var t_qz:Number=m_z;
		var t_qw:Number=m_w;
		m_x=t_qw*t_v.m_x+t_qy*t_v.m_z-t_qz*t_v.m_y;
		m_y=t_qw*t_v.m_y-t_qx*t_v.m_z+t_qz*t_v.m_x;
		m_z=t_qw*t_v.m_z+t_qx*t_v.m_y-t_qy*t_v.m_x;
		m_w=-t_qx*t_v.m_x-t_qy*t_v.m_y-t_qz*t_v.m_z;
		return this;
	}
	public function p_multQuaternionLocal(t_q:c_CalQuaternion):c_CalQuaternion{
		var t_qx:Number=m_x;
		var t_qy:Number=m_y;
		var t_qz:Number=m_z;
		var t_qw:Number=m_w;
		m_x=t_qw*t_q.m_x+t_qx*t_q.m_w+t_qy*t_q.m_z-t_qz*t_q.m_y;
		m_y=t_qw*t_q.m_y-t_qx*t_q.m_z+t_qy*t_q.m_w+t_qz*t_q.m_x;
		m_z=t_qw*t_q.m_z+t_qx*t_q.m_y-t_qy*t_q.m_x+t_qz*t_q.m_w;
		m_w=t_qw*t_q.m_w-t_qx*t_q.m_x-t_qy*t_q.m_y-t_qz*t_q.m_z;
		return this;
	}
	public function p_assign(t_other:c_CalQuaternion):void{
		m_x=t_other.m_x;
		m_y=t_other.m_y;
		m_z=t_other.m_z;
		m_w=t_other.m_w;
	}
	public function p_blend(t_d:Number,t_q:c_CalQuaternion):void{
		var t_norm:Number=m_x*t_q.m_x+m_y*t_q.m_y+m_z*t_q.m_z+m_w*t_q.m_w;
		var t_bFlip:Boolean=false;
		if(t_norm<0.0){
			t_norm=-t_norm;
			t_bFlip=true;
		}
		var t_inv_d:Number=.0;
		if(1.0-t_norm<1e-6){
			t_inv_d=1.0-t_d;
		}else{
			var t_theta:Number=(Math.acos(t_norm)*R2D);
			var t_s:Number=1.0/Math.sin((t_theta)*D2R);
			t_inv_d=Math.sin(((1.0-t_d)*t_theta)*D2R)*t_s;
			t_d=Math.sin((t_d*t_theta)*D2R)*t_s;
		}
		if(t_bFlip){
			t_d=-t_d;
		}
		m_x=t_inv_d*m_x+t_d*t_q.m_x;
		m_y=t_inv_d*m_y+t_d*t_q.m_y;
		m_z=t_inv_d*m_z+t_d*t_q.m_z;
		m_w=t_inv_d*m_w+t_d*t_q.m_w;
	}
}
class c_CalVector extends Object{
	internal var m_x:Number=.0;
	internal var m_y:Number=.0;
	internal var m_z:Number=.0;
	public function m_CalVector_new():c_CalVector{
		m_x=0.0;
		m_y=0.0;
		m_z=0.0;
		return this;
	}
	public function m_CalVector_new2(t_other:c_CalVector):c_CalVector{
		m_x=t_other.m_x;
		m_y=t_other.m_y;
		m_z=t_other.m_z;
		return this;
	}
	public function m_CalVector_new3(t_xx:Number,t_yy:Number,t_zz:Number):c_CalVector{
		m_x=t_xx;
		m_y=t_yy;
		m_z=t_zz;
		return this;
	}
	public function p_multQuaternionLocal(t_q:c_CalQuaternion):c_CalVector{
		var t_temp:c_CalQuaternion=(new c_CalQuaternion).m_CalQuaternion_new3(-t_q.m_x,-t_q.m_y,-t_q.m_z,t_q.m_w);
		t_temp.p_multVectorLocal(this).p_multQuaternionLocal(t_q);
		m_x=t_temp.m_x;
		m_y=t_temp.m_y;
		m_z=t_temp.m_z;
		return this;
	}
	public function p_assign2(t_v:c_CalVertex):void{
		m_x=t_v.m_position.m_x;
		m_y=t_v.m_position.m_y;
		m_z=t_v.m_position.m_z;
	}
	public function p_assign3(t_xx:Number,t_yy:Number,t_zz:Number):void{
		m_x=t_xx;
		m_y=t_yy;
		m_z=t_zz;
	}
	public function p_assign4(t_v:c_CalVector):void{
		m_x=t_v.m_x;
		m_y=t_v.m_y;
		m_z=t_v.m_z;
	}
	public function p_multMatrixLocal(t_m:c_CalMatrix):c_CalVector{
		var t_ox:Number=m_x;
		var t_oy:Number=m_y;
		var t_oz:Number=m_z;
		m_x=t_m.m_dxdx*t_ox+t_m.m_dxdy*t_oy+t_m.m_dxdz*t_oz;
		m_y=t_m.m_dydx*t_ox+t_m.m_dydy*t_oy+t_m.m_dydz*t_oz;
		m_z=t_m.m_dzdx*t_ox+t_m.m_dzdy*t_oy+t_m.m_dzdz*t_oz;
		return this;
	}
	public function p_addLocal(t_v:c_CalVector):c_CalVector{
		m_x+=t_v.m_x;
		m_y+=t_v.m_y;
		m_z+=t_v.m_z;
		return this;
	}
	public function p_blend2(t_d:Number,t_v:c_CalVector):void{
		m_x+=t_d*(t_v.m_x-m_x);
		m_y+=t_d*(t_v.m_y-m_y);
		m_z+=t_d*(t_v.m_z-m_z);
	}
	public function p_multScalarLocal(t_factor:Number):c_CalVector{
		m_x*=t_factor;
		m_y*=t_factor;
		m_z*=t_factor;
		return this;
	}
	public function p_normalize():Number{
		var t_len:Number=Math.sqrt(m_x*m_x+m_y*m_y+m_z*m_z);
		m_x/=t_len;
		m_y/=t_len;
		m_z/=t_len;
		return t_len;
	}
	public function p_subLocal(t_v:c_CalVector):c_CalVector{
		m_x-=t_v.m_x;
		m_y-=t_v.m_y;
		m_z-=t_v.m_z;
		return this;
	}
	public function p_clear():void{
		m_x=0.0;
		m_y=0.0;
		m_z=0.0;
	}
	public function p_length():Number{
		return Math.sqrt(m_x*m_x+m_y*m_y+m_z*m_z);
	}
}
class c_CalBoundingBox extends Object{
	internal var m_plane:Array=[];
	public function m_CalBoundingBox_new():c_CalBoundingBox{
		m_plane=new_object_array(6);
		for(var t_i:int=0;t_i<=5;t_i=t_i+1){
			m_plane[t_i]=(new c_CalPlane).m_CalPlane_new();
		}
		return this;
	}
}
class c_CalPlane extends Object{
	internal var m_a:Number=.0;
	internal var m_b:Number=.0;
	internal var m_c:Number=.0;
	internal var m_d:Number=.0;
	public function p_setNormal(t_n:c_CalVector):void{
		m_a=t_n.m_x;
		m_b=t_n.m_y;
		m_c=t_n.m_z;
		m_d=-1e32;
	}
	public function p_eval(t_p:c_CalVector):Number{
		return t_p.m_x*m_a+t_p.m_y*m_b+t_p.m_z*m_c+m_d;
	}
	public function p_setPosition(t_p:c_CalVector):void{
		m_d=-t_p.m_x*m_a-t_p.m_y*m_b-t_p.m_z*m_c;
	}
	public function m_CalPlane_new():c_CalPlane{
		m_a=0.0;
		m_b=0.0;
		m_c=0.0;
		m_d=0.0;
		return this;
	}
	public function p_dist(t_p:c_CalVector):Number{
		return bb_math2_Abs2((t_p.m_x*m_a+t_p.m_y*m_b+t_p.m_z*m_c+m_d)/Math.sqrt(m_a*m_a+m_b*m_b+m_c*m_c));
	}
}
class c_CalVertex extends Object{
	internal var m_position:c_CalVector=null;
	internal var m_vectorInfluence:Array=[];
	internal var m_faceCollapseCount:int=0;
	internal var m_collapseId:int=0;
	internal var m_normal:c_CalVector=null;
	public function m_CalVertex_new():c_CalVertex{
		m_position=(new c_CalVector).m_CalVector_new();
		m_normal=(new c_CalVector).m_CalVector_new();
		m_vectorInfluence=new_object_array(0);
		m_collapseId=0;
		m_faceCollapseCount=0;
		return this;
	}
	public function m_CalVertex_new2(t_p:c_CalVector):c_CalVertex{
		m_position=(new c_CalVector).m_CalVector_new2(t_p);
		m_normal=(new c_CalVector).m_CalVector_new();
		m_vectorInfluence=new_object_array(0);
		m_collapseId=0;
		m_faceCollapseCount=0;
		return this;
	}
	public function m_CalVertex_new3(t_p:c_CalVector,t_n:c_CalVector):c_CalVertex{
		m_position=(new c_CalVector).m_CalVector_new2(t_p);
		m_normal=(new c_CalVector).m_CalVector_new2(t_n);
		m_vectorInfluence=new_object_array(0);
		m_collapseId=0;
		m_faceCollapseCount=0;
		return this;
	}
	public function m_CalVertex_new4(t_p:c_CalVector,t_n:c_CalVector,t_i:Array,t_c:int,t_fcc:int):c_CalVertex{
		m_position=(new c_CalVector).m_CalVector_new2(t_p);
		m_normal=(new c_CalVector).m_CalVector_new2(t_n);
		m_vectorInfluence=resize_object_array(t_i,t_i.length);
		m_collapseId=t_c;
		m_faceCollapseCount=t_fcc;
		return this;
	}
}
class c_CalCoreSubmesh extends Object{
	internal var m_m_vectorSpring:Array=[];
	public function p_getSpringCount():int{
		return m_m_vectorSpring.length;
	}
	internal var m_m_vectorVertex:Array=[];
	public function p_getVectorVertex():Array{
		return m_m_vectorVertex;
	}
	internal var m_m_vectorCoreSubMorphTarget:Array=[];
	public function p_getCoreSubMorphTargetCount():int{
		return m_m_vectorCoreSubMorphTarget.length;
	}
	internal var m_m_vectorFace:Array=[];
	public function p_getFaceCount():int{
		return m_m_vectorFace.length;
	}
	internal var m_m_lodCount:int=0;
	public function p_getLodCount():int{
		return m_m_lodCount;
	}
	public function p_getVertexCount():int{
		return m_m_vectorVertex.length;
	}
	public function p_getVectorFace():Array{
		return m_m_vectorFace;
	}
	internal var m_m_vectorvectorTangentSpace:Array=[];
	public function p_getVectorVectorTangentSpace():Array{
		return m_m_vectorvectorTangentSpace;
	}
	internal var m_m_vectorPhysicalProperty:Array=[];
	public function p_getVectorPhysicalProperty():Array{
		return m_m_vectorPhysicalProperty;
	}
	public function p_getVectorCoreSubMorphTarget():Array{
		return m_m_vectorCoreSubMorphTarget;
	}
	internal var m_m_vectorTangentsEnabled:Array=[];
	public function p_isTangentsEnabled(t_mapId:int):Boolean{
		if(t_mapId<0 || t_mapId>=m_m_vectorTangentsEnabled.length){
			return false;
		}
		return m_m_vectorTangentsEnabled[t_mapId];
	}
	public function p_getVectorSpring():Array{
		return m_m_vectorSpring;
	}
	internal var m_m_vectorvectorTextureCoordinate:Array=[];
	public function p_getVectorVectorTextureCoordinate():Array{
		return m_m_vectorvectorTextureCoordinate;
	}
	public function m_CalCoreSubmesh_new():c_CalCoreSubmesh{
		return this;
	}
	public function p_setLodCount(t_lodCount:int):void{
		m_m_lodCount=t_lodCount;
	}
	internal var m_m_coreMaterialThreadId:int=0;
	public function p_setCoreMaterialThreadId(t_coreMaterialThreadId:int):void{
		m_m_coreMaterialThreadId=t_coreMaterialThreadId;
	}
	public function p_reserve(t_vertexCount:int,t_textureCoordinateCount:int,t_faceCount:int,t_springCount:int):Boolean{
		m_m_vectorVertex=new_object_array(t_vertexCount);
		m_m_vectorTangentsEnabled=new_bool_array(t_textureCoordinateCount);
		m_m_vectorvectorTangentSpace=new_array_array(t_textureCoordinateCount);
		m_m_vectorvectorTextureCoordinate=new_array_array(t_textureCoordinateCount);
		for(var t_textureCoordinateId:int=0;t_textureCoordinateId<=t_textureCoordinateCount-1;t_textureCoordinateId=t_textureCoordinateId+1){
			m_m_vectorvectorTextureCoordinate[t_textureCoordinateId]=new_object_array(t_vertexCount);
			if(m_m_vectorTangentsEnabled[t_textureCoordinateId]==true){
				m_m_vectorvectorTangentSpace[t_textureCoordinateId]=new_object_array(t_vertexCount);
			}else{
				m_m_vectorvectorTangentSpace[t_textureCoordinateId]=new_object_array(0);
			}
		}
		m_m_vectorFace=new_object_array(t_faceCount);
		m_m_vectorSpring=new_object_array(t_springCount);
		if(t_springCount>0){
			m_m_vectorPhysicalProperty=new_object_array(t_vertexCount);
		}
		return true;
	}
	public function p_setTextureCoordinate(t_vertexId:int,t_textureCoordinateId:int,t_textureCoordinate:c_CalTextureCoordinate):Boolean{
		if(t_textureCoordinateId<0 || t_textureCoordinateId>=m_m_vectorvectorTextureCoordinate.length){
			return false;
		}
		if(t_vertexId<0 || t_vertexId>=m_m_vectorvectorTextureCoordinate[t_textureCoordinateId].length){
			return false;
		}
		m_m_vectorvectorTextureCoordinate[t_textureCoordinateId][t_vertexId]=t_textureCoordinate;
		return true;
	}
	public function p_setVertex(t_vertexId:int,t_vertex:c_CalVertex):Boolean{
		if(t_vertexId<0 || t_vertexId>=m_m_vectorVertex.length){
			return false;
		}
		m_m_vectorVertex[t_vertexId]=t_vertex;
		return true;
	}
	public function p_setFace(t_faceId:int,t_face:c_CalFace):Boolean{
		if(t_faceId<0 || t_faceId>=m_m_vectorFace.length){
			return false;
		}
		m_m_vectorFace[t_faceId]=t_face;
		return true;
	}
}
class c_CalSpring extends Object{
	internal var m_vertexId:Array=new_number_array(2);
	internal var m_idleLength:Number=.0;
}
class c_CalInfluence extends Object{
	internal var m_boneId:int=0;
	internal var m_weight:Number=.0;
	public function m_CalInfluence_new():c_CalInfluence{
		m_boneId=0;
		m_weight=0.0;
		return this;
	}
	public function m_CalInfluence_new2(t_b:int,t_w:Number):c_CalInfluence{
		m_boneId=t_b;
		m_weight=t_w;
		return this;
	}
}
class c_CalModel extends Object{
	internal var m_m_coreModel:c_CalCoreModel=null;
	internal var m_m_skeleton:c_CalSkeleton=null;
	public function p_getCoreModel():c_CalCoreModel{
		return m_m_coreModel;
	}
	internal var m_m_mixer:c_CalMixer=null;
	internal var m_m_morphTargetMixer:c_CalMorphTargetMixer=null;
	internal var m_m_physique:c_CalPhysique=null;
	internal var m_m_springSystem:c_CalSpringSystem=null;
	internal var m_m_renderer:c_CalRenderer=null;
	internal var m_m_userData:Object=null;
	internal var m_m_vectorMesh:Array=[];
	internal var m_m_boundingBox:c_CalBoundingBox=null;
	public function m_CalModel_new():c_CalModel{
		m_m_coreModel=null;
		m_m_skeleton=null;
		m_m_mixer=(new c_CalMixer).m_CalMixer_new2();
		m_m_morphTargetMixer=(new c_CalMorphTargetMixer).m_CalMorphTargetMixer_new();
		m_m_physique=(new c_CalPhysique).m_CalPhysique_new();
		m_m_springSystem=(new c_CalSpringSystem).m_CalSpringSystem_new();
		m_m_renderer=(new c_CalRenderer).m_CalRenderer_new();
		m_m_userData=null;
		m_m_vectorMesh=new_object_array(0);
		m_m_boundingBox=(new c_CalBoundingBox).m_CalBoundingBox_new();
		return this;
	}
	public function m_CalModel_new2(t_coreModel:c_CalCoreModel):c_CalModel{
		m_m_coreModel=t_coreModel;
		m_m_skeleton=(new c_CalSkeleton).m_CalSkeleton_new2(t_coreModel.p_getCoreSkeleton());
		m_m_mixer=(new c_CalMixer).m_CalMixer_new(this);
		m_m_morphTargetMixer=(new c_CalMorphTargetMixer).m_CalMorphTargetMixer_new2(this);
		m_m_physique=(new c_CalPhysique).m_CalPhysique_new2(this);
		m_m_springSystem=(new c_CalSpringSystem).m_CalSpringSystem_new2(this);
		m_m_renderer=(new c_CalRenderer).m_CalRenderer_new2(this);
		m_m_userData=null;
		m_m_vectorMesh=new_object_array(0);
		m_m_boundingBox=(new c_CalBoundingBox).m_CalBoundingBox_new();
		return this;
	}
	public function p_attachMesh(t_coreMeshId:int):Boolean{
		if(t_coreMeshId<0 || t_coreMeshId>=m_m_coreModel.p_getCoreMeshCount()){
			print("Invalid Mesh ID 8===D -o -o");
			return false;
		}
		var t_coreMesh:c_CalCoreMesh=m_m_coreModel.p_getCoreMesh(t_coreMeshId);
		for(var t_meshId:int=0;t_meshId<=m_m_vectorMesh.length-1;t_meshId=t_meshId+1){
			if(m_m_vectorMesh[t_meshId].p_getCoreMesh2()==t_coreMesh){
				return true;
			}
		}
		var t_mesh:c_CalMesh=(new c_CalMesh).m_CalMesh_new2(t_coreMesh);
		t_mesh.p_setModel(this);
		m_m_vectorMesh=resize_object_array(m_m_vectorMesh,m_m_vectorMesh.length+1);
		m_m_vectorMesh[m_m_vectorMesh.length-1]=t_mesh;
		return true;
	}
	public function p_getRenderer():c_CalRenderer{
		return m_m_renderer;
	}
	public function p_getVectorMesh():Array{
		return m_m_vectorMesh;
	}
	public function p_getPhysique():c_CalPhysique{
		return m_m_physique;
	}
	public function p_getSkeleton():c_CalSkeleton{
		return m_m_skeleton;
	}
	public function p_getMixer():c_CalMixer{
		if(m_m_mixer==null){
			return null;
		}
		if(m_m_mixer.p_isDefaultMixer()==false){
			print("Invalid Mixer");
			return null;
		}
		return m_m_mixer;
	}
	public function p_getUserData():Object{
		return m_m_userData;
	}
	public function p_getMesh(t_coreMeshId:int):c_CalMesh{
		if(t_coreMeshId<0 || t_coreMeshId>=m_m_coreModel.p_getCoreMeshCount()){
			print("Invalid Mesh ID");
			return null;
		}
		var t_coreMesh:c_CalCoreMesh=m_m_coreModel.p_getCoreMesh(t_coreMeshId);
		for(var t_meshId:int=0;t_meshId<=m_m_vectorMesh.length-1;t_meshId=t_meshId+1){
			if(m_m_vectorMesh[t_meshId].p_getCoreMesh2()==t_coreMesh){
				return m_m_vectorMesh[t_meshId];
			}
		}
		return null;
	}
	public function p_update(t_deltaTime:Number):void{
		m_m_mixer.p_updateAnimation(t_deltaTime);
		m_m_mixer.p_updateSkeleton();
		m_m_morphTargetMixer.p_update(t_deltaTime);
		m_m_physique.p_update2();
		m_m_springSystem.p_update(t_deltaTime);
	}
}
class c_CalSkeleton extends Object{
	internal var m_m_coreSkeleton:c_CalCoreSkeleton=null;
	internal var m_m_vectorBone:Array=[];
	internal var m_m_isBoundingBoxesComputed:Boolean=false;
	public function m_CalSkeleton_new():c_CalSkeleton{
		m_m_coreSkeleton=null;
		m_m_vectorBone=new_object_array(0);
		m_m_isBoundingBoxesComputed=false;
		return this;
	}
	public function m_CalSkeleton_new2(t_coreSkeleton:c_CalCoreSkeleton):c_CalSkeleton{
		m_m_coreSkeleton=t_coreSkeleton;
		m_m_vectorBone=new_object_array(0);
		m_m_isBoundingBoxesComputed=false;
		var t_vectorCoreBone:Array=t_coreSkeleton.p_getVectorCoreBone();
		var t_boneCount:int=t_vectorCoreBone.length;
		for(var t_boneId:int=0;t_boneId<=t_boneCount-1;t_boneId=t_boneId+1){
			var t_bone:c_CalBone=(new c_CalBone).m_CalBone_new2(t_vectorCoreBone[t_boneId]);
			t_bone.p_setSkeleton(this);
			m_m_vectorBone=resize_object_array(m_m_vectorBone,m_m_vectorBone.length+1);
			m_m_vectorBone[m_m_vectorBone.length-1]=t_bone;
		}
		return this;
	}
	public function p_getVectorBone():Array{
		return m_m_vectorBone;
	}
	public function p_clearState():void{
		for(var t_boneId:int=0;t_boneId<=m_m_vectorBone.length-1;t_boneId=t_boneId+1){
			m_m_vectorBone[t_boneId].p_clearState();
		}
		m_m_isBoundingBoxesComputed=false;
	}
	public function p_lockState():void{
		for(var t_boneId:int=0;t_boneId<=m_m_vectorBone.length-1;t_boneId=t_boneId+1){
			m_m_vectorBone[t_boneId].p_lockState();
		}
	}
	public function p_getBone(t_boneId:int):c_CalBone{
		return m_m_vectorBone[t_boneId];
	}
	public function p_calculateState():void{
		var t_listRootCoreBoneId:Array=m_m_coreSkeleton.p_getVectorRootCoreBoneId();
		for(var t_iRootCoreBoneId:int=0;t_iRootCoreBoneId<=t_listRootCoreBoneId.length-1;t_iRootCoreBoneId=t_iRootCoreBoneId+1){
			m_m_vectorBone[t_listRootCoreBoneId[t_iRootCoreBoneId]].p_calculateState();
		}
		m_m_isBoundingBoxesComputed=false;
	}
}
class c_CalAbstractMixer extends Object{
	public function m_CalAbstractMixer_new():c_CalAbstractMixer{
		return this;
	}
	public function m_CalAbstractMixer_new2(t_model:c_CalModel):c_CalAbstractMixer{
		return this;
	}
	public function p_isDefaultMixer():Boolean{
		return false;
	}
	public function p_updateAnimation(t_deltaTime:Number):void{
		print("This is the abstract mixer! Use one of the extended classes!");
	}
	public function p_updateSkeleton():void{
		print("This is the abstract mixer! Use one of the extended classes!");
	}
}
class c_CalMixer extends c_CalAbstractMixer{
	internal var m_m_model:c_CalModel=null;
	internal var m_m_vectorAnimation:Array=[];
	internal var m_m_listAnimationAction:Array=[];
	internal var m_m_listAnimationCycle:Array=[];
	internal var m_m_animationTime:Number=.0;
	internal var m_m_animationDuration:Number=.0;
	internal var m_m_timeFactor:Number=.0;
	public function m_CalMixer_new(t_model:c_CalModel):c_CalMixer{
		super.m_CalAbstractMixer_new();
		m_m_model=t_model;
		m_m_vectorAnimation=new_object_array(t_model.p_getCoreModel().p_getCoreAnimationCount());
		m_m_listAnimationAction=new_object_array(0);
		m_m_listAnimationCycle=new_object_array(0);
		m_m_animationTime=0.0;
		m_m_animationDuration=0.0;
		m_m_timeFactor=1.0;
		return this;
	}
	public function m_CalMixer_new2():c_CalMixer{
		super.m_CalAbstractMixer_new();
		return this;
	}
	public override function p_isDefaultMixer():Boolean{
		return true;
	}
	public function p_blendCycle(t_id:int,t_weight:Number,t_delay:Number):Boolean{
		if(t_id<0 || t_id>=m_m_vectorAnimation.length){
			print("Invalid Animation ID");
			return false;
		}
		var t_animation:c_CalAnimation=m_m_vectorAnimation[t_id];
		if(t_animation==null){
			if(t_weight==0.0){
				return true;
			}
			var t_coreAnimation:c_CalCoreAnimation=m_m_model.p_getCoreModel().p_getCoreAnimation(t_id);
			if(t_coreAnimation==null){
				return false;
			}
			bb_mixer_addExtraKeyframeForLoopedAnim(t_coreAnimation);
			var t_animationCycle:c_CalAnimationCycle=(new c_CalAnimationCycle).m_CalAnimationCycle_new2(t_coreAnimation);
			m_m_vectorAnimation[t_id]=(t_animationCycle);
			var t_lac:Array=new_object_array(m_m_listAnimationCycle.length+1);
			for(var t_i:int=1;t_i<=m_m_listAnimationCycle.length;t_i=t_i+1){
				t_lac[t_i]=m_m_listAnimationCycle[t_i-1];
			}
			t_lac[0]=t_animationCycle;
			m_m_listAnimationCycle=t_lac;
			return t_animationCycle.p_blend3(t_weight,t_delay);
		}
		if(t_animation.p_getType()!=1){
			print("Not Animation Cycle Class");
			return false;
		}
		if(t_weight==0.0){
			m_m_vectorAnimation[t_id]=null;
		}
		var t_animationCycle2:c_CalAnimationCycle=((t_animation) as c_CalAnimationCycle);
		t_animationCycle2.p_blend3(t_weight,t_delay);
		t_animationCycle2.p_checkCallbacks(0.0,m_m_model);
		return true;
	}
	public override function p_updateAnimation(t_deltaTime:Number):void{
		if(m_m_animationDuration==0.0){
			m_m_animationTime=0.0;
		}else{
			m_m_animationTime+=t_deltaTime*m_m_timeFactor;
			if(m_m_animationTime>=m_m_animationDuration || m_m_animationTime<0.0){
				m_m_animationTime=bb_animation_Modf(m_m_animationTime,m_m_animationDuration);
			}
			if(m_m_animationTime<0.0){
				m_m_animationTime=m_m_animationTime+m_m_animationDuration;
			}
		}
		var t_animationActionId:int=0;
		while(t_animationActionId<m_m_listAnimationAction.length){
			var t_animationAction:c_CalAnimationAction=m_m_listAnimationAction[t_animationActionId];
			if(t_animationAction.p_update(t_deltaTime)){
				t_animationAction.p_checkCallbacks(t_animationAction.p_getTime(),m_m_model);
				t_animationActionId=t_animationActionId+1;
			}else{
				t_animationAction.p_completeCallbacks(m_m_model);
				var t_laa:Array=new_object_array(m_m_listAnimationAction.length-1);
				var t_pos:int=0;
				for(var t_i:int=0;t_i<=m_m_listAnimationAction.length-1;t_i=t_i+1){
					if(t_i!=t_animationActionId){
						t_laa[t_pos]=m_m_listAnimationAction[t_i];
						t_pos=t_pos+1;
					}
				}
				m_m_listAnimationAction=t_laa;
			}
		}
		var t_accumulatedWeight:Number=0.0;
		var t_accumulatedDuration:Number=0.0;
		var t_animationCycleId:int=0;
		while(t_animationCycleId<m_m_listAnimationCycle.length){
			var t_animationCycle:c_CalAnimationCycle=m_m_listAnimationCycle[t_animationCycleId];
			if(t_animationCycle.p_update(t_deltaTime)==true){
				if(t_animationCycle.p_getState()==1){
					t_accumulatedWeight+=t_animationCycle.p_getWeight();
					t_accumulatedDuration+=t_animationCycle.p_getWeight()*t_animationCycle.p_getCoreAnimation2().p_getDuration();
				}
				t_animationCycle.p_checkCallbacks(m_m_animationTime,m_m_model);
				t_animationCycleId=t_animationCycleId+1;
			}else{
				t_animationCycle.p_completeCallbacks(m_m_model);
				var t_lac:Array=new_object_array(m_m_listAnimationCycle.length-1);
				var t_pos2:int=0;
				for(var t_i2:int=0;t_i2<=m_m_listAnimationCycle.length-1;t_i2=t_i2+1){
					if(t_i2!=t_animationCycleId){
						t_lac[t_pos2]=m_m_listAnimationCycle[t_i2];
						t_pos2=t_pos2+1;
					}
				}
				m_m_listAnimationCycle=t_lac;
			}
		}
		if(t_accumulatedWeight>0.0){
			m_m_animationDuration=t_accumulatedDuration/t_accumulatedWeight;
		}else{
			m_m_animationDuration=0.0;
		}
	}
	public override function p_updateSkeleton():void{
		var t_skeleton:c_CalSkeleton=m_m_model.p_getSkeleton();
		if(t_skeleton==null){
			return;
		}
		t_skeleton.p_clearState();
		var t_vectorBone:Array=t_skeleton.p_getVectorBone();
		var t_translation:c_CalVector=(new c_CalVector).m_CalVector_new();
		var t_rotation:c_CalQuaternion=(new c_CalQuaternion).m_CalQuaternion_new();
		for(var t_animationActionId:int=0;t_animationActionId<=m_m_listAnimationAction.length-1;t_animationActionId=t_animationActionId+1){
			var t_animationAction:c_CalAnimationAction=m_m_listAnimationAction[t_animationActionId];
			var t_coreAnimation:c_CalCoreAnimation=t_animationAction.p_getCoreAnimation2();
			var t_listCoreTrack:Array=t_coreAnimation.p_getListCoreTrack();
			for(var t_coreTrackId:int=0;t_coreTrackId<=t_listCoreTrack.length-1;t_coreTrackId=t_coreTrackId+1){
				var t_bone:c_CalBone=t_vectorBone[t_listCoreTrack[t_coreTrackId].p_getCoreBoneId2()];
				t_listCoreTrack[t_coreTrackId].p_getState2(t_animationAction.p_getTime(),t_translation,t_rotation);
				t_bone.p_blendState(t_animationAction.p_getWeight(),t_translation,t_rotation);
			}
		}
		t_skeleton.p_lockState();
		for(var t_animationCycleId:int=0;t_animationCycleId<=m_m_listAnimationCycle.length-1;t_animationCycleId=t_animationCycleId+1){
			var t_animationCycle:c_CalAnimationCycle=m_m_listAnimationCycle[t_animationCycleId];
			var t_coreAnimation2:c_CalCoreAnimation=t_animationCycle.p_getCoreAnimation2();
			var t_animationTime:Number=.0;
			if(t_animationCycle.p_getState()==1){
				if(m_m_animationDuration==0.0){
					t_animationTime=0.0;
				}else{
					t_animationTime=m_m_animationTime*t_coreAnimation2.p_getDuration()/m_m_animationDuration;
				}
			}else{
				t_animationTime=t_animationCycle.p_getTime();
			}
			var t_listCoreTrack2:Array=t_coreAnimation2.p_getListCoreTrack();
			for(var t_coreTrackId2:int=0;t_coreTrackId2<=t_listCoreTrack2.length-1;t_coreTrackId2=t_coreTrackId2+1){
				var t_bone2:c_CalBone=t_vectorBone[t_listCoreTrack2[t_coreTrackId2].p_getCoreBoneId2()];
				t_listCoreTrack2[t_coreTrackId2].p_getState2(t_animationTime,t_translation,t_rotation);
				t_bone2.p_blendState(t_animationCycle.p_getWeight(),t_translation,t_rotation);
			}
		}
		t_skeleton.p_lockState();
		t_skeleton.p_calculateState();
	}
}
class c_CalAnimation extends Object{
	internal var m_m_coreAnimation:c_CalCoreAnimation=null;
	internal var m_m_lastCallbackTimes:Array=[];
	internal var m_m_type:int=0;
	internal var m_m_state:int=0;
	internal var m_m_time:Number=.0;
	internal var m_m_timeFactor:Number=.0;
	internal var m_m_weight:Number=.0;
	public function m_CalAnimation_new():c_CalAnimation{
		m_m_coreAnimation=null;
		m_m_lastCallbackTimes=new_number_array(0);
		m_m_type=0;
		m_m_state=0;
		m_m_time=0.0;
		m_m_timeFactor=0.0;
		m_m_weight=0.0;
		return this;
	}
	public function m_CalAnimation_new2(t_coreAnimation:c_CalCoreAnimation):c_CalAnimation{
		m_m_coreAnimation=t_coreAnimation;
		m_m_lastCallbackTimes=new_number_array(0);
		m_m_type=0;
		m_m_state=0;
		m_m_time=0.0;
		m_m_timeFactor=1.0;
		m_m_weight=0.0;
		var t_callbackList:Array=t_coreAnimation.p_getCallbackList();
		for(var t_i:int=0;t_i<=t_callbackList.length-1;t_i=t_i+1){
			m_m_lastCallbackTimes=resize_number_array(m_m_lastCallbackTimes,m_m_lastCallbackTimes.length+1);
			m_m_lastCallbackTimes[m_m_lastCallbackTimes.length-1]=0.0;
		}
		return this;
	}
	public function p_setType(t_type:int):void{
		m_m_type=t_type;
	}
	public function p_setState(t_state:int):void{
		m_m_state=t_state;
	}
	public function p_setWeight(t_weight:Number):void{
		m_m_weight=t_weight;
	}
	public function p_getType():int{
		return m_m_type;
	}
	public function p_checkCallbacks(t_animationTime:Number,t_model:c_CalModel):void{
		var t_callbackList:Array=m_m_coreAnimation.p_getCallbackList();
		for(var t_i:int=0;t_i<=t_callbackList.length-1;t_i=t_i+1){
			if(m_m_lastCallbackTimes.length<=t_i){
				m_m_lastCallbackTimes=resize_number_array(m_m_lastCallbackTimes,m_m_lastCallbackTimes.length+1);
				m_m_lastCallbackTimes[m_m_lastCallbackTimes.length-1]=t_animationTime;
			}
			t_callbackList[t_i].m_callback.p_AnimationUpdate(t_animationTime,t_model,t_model.p_getUserData());
			if(t_animationTime>0.0 && t_animationTime<m_m_lastCallbackTimes[t_i]){
				m_m_lastCallbackTimes[t_i]-=m_m_coreAnimation.p_getDuration();
			}else{
				if(t_animationTime<0.0 && t_animationTime>m_m_lastCallbackTimes[t_i]){
					m_m_lastCallbackTimes[t_i]+=m_m_coreAnimation.p_getDuration();
				}
			}
			if(t_animationTime>=0.0 && t_animationTime>=m_m_lastCallbackTimes[t_i]+t_callbackList[t_i].m_min_interval || t_animationTime<0.0 && t_animationTime<=m_m_lastCallbackTimes[t_i]-t_callbackList[t_i].m_min_interval){
				t_callbackList[t_i].m_callback.p_AnimationUpdate(t_animationTime,t_model,t_model.p_getUserData());
				m_m_lastCallbackTimes[t_i]=t_animationTime;
			}
		}
	}
	public function p_getState():int{
		return m_m_state;
	}
	public function p_getTime():Number{
		return m_m_time;
	}
	public function p_getTimeFactor():Number{
		return m_m_timeFactor;
	}
	public function p_setTime(t_time:Number):void{
		m_m_time=t_time;
	}
	public function p_getCoreAnimation2():c_CalCoreAnimation{
		return m_m_coreAnimation;
	}
	public function p_completeCallbacks(t_model:c_CalModel):void{
		var t_callbackList:Array=m_m_coreAnimation.p_getCallbackList();
		for(var t_i:int=0;t_i<=t_callbackList.length-1;t_i=t_i+1){
			t_callbackList[t_i].m_callback.p_AnimationComplete(t_model,t_model.p_getUserData());
		}
	}
	public function p_getWeight():Number{
		return m_m_weight;
	}
}
class c_CalAnimationAction extends c_CalAnimation{
	internal var m_m_delayIn:Number=.0;
	internal var m_m_weightTarget:Number=.0;
	internal var m_m_autoLock:Boolean=false;
	internal var m_m_delayOut:Number=.0;
	public function p_update(t_deltaTime:Number):Boolean{
		if(this.p_getState()!=6){
			this.p_setTime(this.p_getTime()+t_deltaTime*this.p_getTimeFactor());
		}
		if(this.p_getState()==3){
			if(this.p_getTime()<m_m_delayIn){
				this.p_setWeight(this.p_getTime()/m_m_delayIn*m_m_weightTarget);
			}else{
				this.p_setState(4);
				this.p_setWeight(m_m_weightTarget);
			}
		}
		if(this.p_getState()==4){
			if(m_m_autoLock==false && this.p_getTime()>=this.p_getCoreAnimation2().p_getDuration()-m_m_delayOut){
				this.p_setState(5);
			}else{
				if(m_m_autoLock==true && this.p_getTime()>this.p_getCoreAnimation2().p_getDuration()){
					this.p_setState(6);
					this.p_setTime(this.p_getCoreAnimation2().p_getDuration());
				}
			}
		}
		if(this.p_getState()==5){
			if(this.p_getTime()<this.p_getCoreAnimation2().p_getDuration()){
				this.p_setWeight((this.p_getCoreAnimation2().p_getDuration()-this.p_getTime())/m_m_delayOut*m_m_weightTarget);
			}else{
				this.p_setWeight(0.0);
				return false;
			}
		}
		return true;
	}
}
class c_CalAnimationCycle extends c_CalAnimation{
	public function m_CalAnimationCycle_new():c_CalAnimationCycle{
		super.m_CalAnimation_new();
		return this;
	}
	internal var m_m_targetDelay:Number=.0;
	internal var m_m_targetWeight:Number=.0;
	public function m_CalAnimationCycle_new2(t_coreAnimation:c_CalCoreAnimation):c_CalAnimationCycle{
		super.m_CalAnimation_new2(t_coreAnimation);
		m_m_targetDelay=0.0;
		m_m_targetWeight=0.0;
		this.p_setType(1);
		this.p_setState(1);
		this.p_setWeight(0.0);
		return this;
	}
	public function p_blend3(t_weight:Number,t_delay:Number):Boolean{
		m_m_targetWeight=t_weight;
		m_m_targetDelay=t_delay;
		return false;
	}
	public function p_update(t_deltaTime:Number):Boolean{
		if(m_m_targetDelay<=bb_math2_Abs2(t_deltaTime)){
			this.p_setWeight(m_m_targetWeight);
			m_m_targetDelay=0.0;
			if(this.p_getWeight()==0.0){
				return false;
			}
		}else{
			var t_factor:Number=t_deltaTime/m_m_targetDelay;
			this.p_setWeight((1.0-t_factor)*this.p_getWeight()+t_factor*m_m_targetWeight);
			m_m_targetDelay-=t_deltaTime;
		}
		if(this.p_getState()==2){
			this.p_setTime(this.p_getTime()+t_deltaTime*this.p_getTimeFactor());
			if(this.p_getTime()>=this.p_getCoreAnimation2().p_getDuration()){
				this.p_setTime(bb_animation_Modf(this.p_getTime(),this.p_getCoreAnimation2().p_getDuration()));
			}
			if(this.p_getTime()<0.0){
				this.p_setTime(this.p_getTime()+this.p_getCoreAnimation2().p_getDuration());
			}
		}
		return true;
	}
}
class c_CalMorphTargetMixer extends Object{
	internal var m_m_model:c_CalModel=null;
	internal var m_m_vectorCurrentWeight:Array=[];
	internal var m_m_vectorEndWeight:Array=[];
	internal var m_m_vectorDuration:Array=[];
	public function m_CalMorphTargetMixer_new():c_CalMorphTargetMixer{
		m_m_model=null;
		m_m_vectorCurrentWeight=new_number_array(0);
		m_m_vectorEndWeight=new_number_array(0);
		m_m_vectorDuration=new_number_array(0);
		return this;
	}
	public function m_CalMorphTargetMixer_new2(t_model:c_CalModel):c_CalMorphTargetMixer{
		m_m_model=t_model;
		var t_morphAnimationCount:int=t_model.p_getCoreModel().p_getCoreMorphAnimationCount();
		m_m_vectorCurrentWeight=new_number_array(t_morphAnimationCount);
		m_m_vectorEndWeight=new_number_array(t_morphAnimationCount);
		m_m_vectorDuration=new_number_array(t_morphAnimationCount);
		return this;
	}
	public function p_update(t_deltaTime:Number):void{
		for(var t_i:int=0;t_i<=m_m_vectorCurrentWeight.length-1;t_i=t_i+1){
			var t_currentWeight:Number=m_m_vectorCurrentWeight[t_i];
			var t_endWeight:Number=m_m_vectorEndWeight[t_i];
			var t_duration:Number=m_m_vectorDuration[t_i];
			if(t_deltaTime>=t_duration){
				m_m_vectorCurrentWeight[t_i]=t_endWeight;
				m_m_vectorDuration[t_i]=0.0;
			}else{
				m_m_vectorCurrentWeight[t_i]+=(t_endWeight-t_currentWeight)*t_deltaTime/t_duration;
				m_m_vectorDuration[t_i]-=t_deltaTime;
			}
		}
		for(var t_morphAnimationID:int=0;t_morphAnimationID<=m_m_vectorCurrentWeight.length-1;t_morphAnimationID=t_morphAnimationID+1){
			var t_coreMorphAnimation:c_CalCoreMorphAnimation=m_m_model.p_getCoreModel().p_getCoreMorphAnimation(t_morphAnimationID);
			var t_vectorCoreMeshID:Array=t_coreMorphAnimation.p_getVectorCoreMeshID();
			var t_vectorMorphTargetID:Array=t_coreMorphAnimation.p_getVectorMorphTargetID();
			for(var t_i2:int=0;t_i2<=t_vectorCoreMeshID.length-1;t_i2=t_i2+1){
				var t_vectorSubmesh:Array=m_m_model.p_getMesh(t_vectorCoreMeshID[t_i2]).p_getVectorSubmesh();
				var t_submeshCount:int=t_vectorSubmesh.length;
				for(var t_submeshId:int=0;t_submeshId<=t_submeshCount-1;t_submeshId=t_submeshId+1){
					t_vectorSubmesh[t_submeshId].p_setMorphTargetWeight(t_vectorMorphTargetID[t_i2],m_m_vectorCurrentWeight[t_morphAnimationID]);
				}
			}
		}
	}
}
class c_CalPhysique extends Object{
	internal var m_m_model:c_CalModel=null;
	internal var m_m_normalize:Boolean=false;
	internal var m_m_axisFactorX:Number=.0;
	internal var m_m_axisFactorY:Number=.0;
	internal var m_m_axisFactorZ:Number=.0;
	public function m_CalPhysique_new():c_CalPhysique{
		m_m_model=null;
		m_m_normalize=false;
		m_m_axisFactorX=0.0;
		m_m_axisFactorY=0.0;
		m_m_axisFactorZ=0.0;
		return this;
	}
	public function m_CalPhysique_new2(t_model:c_CalModel):c_CalPhysique{
		m_m_model=t_model;
		m_m_normalize=true;
		m_m_axisFactorX=1.0;
		m_m_axisFactorY=1.0;
		m_m_axisFactorZ=1.0;
		return this;
	}
	public function p_calculateVertices(t_submesh:c_CalSubmesh,t_vertexBuffer:Array,t_stride:int):int{
		if(t_stride<=0){
			t_stride=3;
		}
		if(t_vertexBuffer.length<t_submesh.p_getVertexCount()*t_stride){
			return 0;
		}
		var t_vectorBone:Array=m_m_model.p_getSkeleton().p_getVectorBone();
		var t_vectorVertex:Array=t_submesh.p_getCoreSubmesh2().p_getVectorVertex();
		var t_vectorPhysicalProperty:Array=t_submesh.p_getCoreSubmesh2().p_getVectorPhysicalProperty();
		var t_vertexCount:int=t_submesh.p_getVertexCount();
		var t_vectorSubMorphTarget:Array=t_submesh.p_getCoreSubmesh2().p_getVectorCoreSubMorphTarget();
		var t_baseWeight:Number=t_submesh.p_getBaseWeight();
		var t_morphTargetCount:int=t_submesh.p_getMorphTargetWeightCount();
		var t_vi:int=0;
		var t_position:c_CalVector=(new c_CalVector).m_CalVector_new();
		var t_v:c_CalVector=(new c_CalVector).m_CalVector_new();
		for(var t_vertexId:int=0;t_vertexId<=t_vertexCount-1;t_vertexId=t_vertexId+1){
			var t_vertex:c_CalVertex=t_vectorVertex[t_vertexId];
			t_position.p_assign3(0.0,0.0,0.0);
			if(t_baseWeight==1.0){
				t_position.m_x=t_vertex.m_position.m_x;
				t_position.m_y=t_vertex.m_position.m_y;
				t_position.m_z=t_vertex.m_position.m_z;
			}else{
				t_position.m_x=t_baseWeight*t_vertex.m_position.m_x;
				t_position.m_y=t_baseWeight*t_vertex.m_position.m_y;
				t_position.m_z=t_baseWeight*t_vertex.m_position.m_z;
				for(var t_morphTargetId:int=0;t_morphTargetId<=t_morphTargetCount-1;t_morphTargetId=t_morphTargetId+1){
					var t_blendVertex:c_CalBlendVertex=t_vectorSubMorphTarget[t_morphTargetId].p_getVectorBlendVertex()[t_vertexId];
					var t_currentWeight:Number=t_submesh.p_getMorphTargetWeight(t_morphTargetId);
					t_position.m_x+=t_currentWeight*t_blendVertex.m_position.m_x;
					t_position.m_y+=t_currentWeight*t_blendVertex.m_position.m_y;
					t_position.m_z+=t_currentWeight*t_blendVertex.m_position.m_z;
				}
			}
			var t_x:Number=.0;
			var t_y:Number=.0;
			var t_z:Number=.0;
			t_x=0.0;
			t_y=0.0;
			t_z=0.0;
			var t_influenceCount:int=t_vertex.m_vectorInfluence.length;
			if(t_influenceCount==0){
				t_x=t_position.m_x;
				t_y=t_position.m_y;
				t_z=t_position.m_z;
			}else{
				for(var t_influenceId:int=0;t_influenceId<=t_influenceCount-1;t_influenceId=t_influenceId+1){
					var t_influence:c_CalInfluence=t_vertex.m_vectorInfluence[t_influenceId];
					var t_bone:c_CalBone=t_vectorBone[t_influence.m_boneId];
					t_v.p_assign4(t_position);
					t_v.p_multMatrixLocal(t_bone.p_getTransformMatrix());
					t_v.p_addLocal(t_bone.p_getTranslationBoneSpace());
					t_x+=t_influence.m_weight*t_v.m_x;
					t_y+=t_influence.m_weight*t_v.m_y;
					t_z+=t_influence.m_weight*t_v.m_z;
				}
			}
			if(t_submesh.p_getCoreSubmesh2().p_getSpringCount()>0 && t_submesh.p_hasInternalData()){
				var t_physicalProperty:c_CalPhysicalProperty=t_vectorPhysicalProperty[t_vertexId];
				if(t_physicalProperty.m_weight==0.0){
					t_vertexBuffer[t_vi]=t_x*m_m_axisFactorX;
					t_vertexBuffer[t_vi+1]=t_y*m_m_axisFactorY;
					t_vertexBuffer[t_vi+2]=t_z*m_m_axisFactorZ;
				}
			}else{
				t_vertexBuffer[t_vi]=t_x*m_m_axisFactorX;
				t_vertexBuffer[t_vi+1]=t_y*m_m_axisFactorY;
				t_vertexBuffer[t_vi+2]=t_z*m_m_axisFactorZ;
			}
			t_vi+=t_stride;
		}
		return t_vertexCount;
	}
	public function p_calculateVerticesAndNormalsInternal(t_submesh:c_CalSubmesh,t_veritces:Array,t_normals:Array):int{
		if(t_veritces.length<t_submesh.p_getVertexCount() || t_normals.length<t_submesh.p_getVertexCount()){
			print("internal error: buffer is not large enough to contain all the vertex/normal data");
			return 0;
		}
		var t_vectorBone:Array=m_m_model.p_getSkeleton().p_getVectorBone();
		var t_vectorVertex:Array=t_submesh.p_getCoreSubmesh2().p_getVectorVertex();
		var t_vectorPhysicalProperty:Array=t_submesh.p_getCoreSubmesh2().p_getVectorPhysicalProperty();
		var t_vertexCount:int=t_submesh.p_getVertexCount();
		var t_vectorSubMorphTarget:Array=t_submesh.p_getCoreSubmesh2().p_getVectorCoreSubMorphTarget();
		var t_baseWeight:Number=t_submesh.p_getBaseWeight();
		var t_morphTargetCount:int=t_submesh.p_getMorphTargetWeightCount();
		var t_v:c_CalVector=(new c_CalVector).m_CalVector_new();
		var t_n:c_CalVector=(new c_CalVector).m_CalVector_new();
		var t_position:c_CalVector=(new c_CalVector).m_CalVector_new();
		var t_normal:c_CalVector=(new c_CalVector).m_CalVector_new();
		for(var t_vertexId:int=0;t_vertexId<=t_vertexCount-1;t_vertexId=t_vertexId+1){
			var t_vertex:c_CalVertex=t_vectorVertex[t_vertexId];
			t_position.p_assign3(0.0,0.0,0.0);
			t_normal.p_assign3(0.0,0.0,0.0);
			if(t_baseWeight==1.0){
				t_position.m_x=t_vertex.m_position.m_x;
				t_position.m_y=t_vertex.m_position.m_y;
				t_position.m_z=t_vertex.m_position.m_z;
				t_normal.m_x=t_vertex.m_normal.m_x;
				t_normal.m_y=t_vertex.m_normal.m_y;
				t_normal.m_z=t_vertex.m_normal.m_z;
			}else{
				t_position.m_x=t_baseWeight*t_vertex.m_position.m_x;
				t_position.m_y=t_baseWeight*t_vertex.m_position.m_y;
				t_position.m_z=t_baseWeight*t_vertex.m_position.m_z;
				t_normal.m_x=t_baseWeight*t_vertex.m_normal.m_x;
				t_normal.m_y=t_baseWeight*t_vertex.m_normal.m_y;
				t_normal.m_z=t_baseWeight*t_vertex.m_normal.m_z;
				for(var t_morphTargetId:int=0;t_morphTargetId<=t_morphTargetCount-1;t_morphTargetId=t_morphTargetId+1){
					var t_blendVertex:c_CalBlendVertex=t_vectorSubMorphTarget[t_morphTargetId].p_getVectorBlendVertex()[t_vertexId];
					var t_currentWeight:Number=t_submesh.p_getMorphTargetWeight(t_morphTargetId);
					t_position.m_x+=t_currentWeight*t_blendVertex.m_position.m_x;
					t_position.m_y+=t_currentWeight*t_blendVertex.m_position.m_y;
					t_position.m_z+=t_currentWeight*t_blendVertex.m_position.m_z;
					t_normal.m_x+=t_currentWeight*t_blendVertex.m_normal.m_x;
					t_normal.m_y+=t_currentWeight*t_blendVertex.m_normal.m_y;
					t_normal.m_z+=t_currentWeight*t_blendVertex.m_normal.m_z;
				}
			}
			var t_x:Number=.0;
			var t_y:Number=.0;
			var t_z:Number=.0;
			t_x=0.0;
			t_y=0.0;
			t_z=0.0;
			var t_nx:Number=.0;
			var t_ny:Number=.0;
			var t_nz:Number=.0;
			t_nx=0.0;
			t_ny=0.0;
			t_nz=0.0;
			var t_influenceCount:int=t_vertex.m_vectorInfluence.length;
			if(t_influenceCount==0){
				t_x=t_position.m_x;
				t_y=t_position.m_y;
				t_z=t_position.m_z;
				t_nx=t_normal.m_x;
				t_ny=t_normal.m_y;
				t_nz=t_normal.m_z;
			}else{
				for(var t_influenceId:int=0;t_influenceId<=t_influenceCount-1;t_influenceId=t_influenceId+1){
					var t_influence:c_CalInfluence=t_vertex.m_vectorInfluence[t_influenceId];
					var t_bone:c_CalBone=t_vectorBone[t_influence.m_boneId];
					t_v.p_assign4(t_position);
					t_v.p_multMatrixLocal(t_bone.p_getTransformMatrix());
					t_v.p_addLocal(t_bone.p_getTranslationBoneSpace());
					t_x+=t_influence.m_weight*t_v.m_x;
					t_y+=t_influence.m_weight*t_v.m_y;
					t_z+=t_influence.m_weight*t_v.m_z;
					t_n.p_assign4(t_normal);
					t_n.p_multMatrixLocal(t_bone.p_getTransformMatrix());
					t_nx+=t_influence.m_weight*t_n.m_x;
					t_ny+=t_influence.m_weight*t_n.m_y;
					t_nz+=t_influence.m_weight*t_n.m_z;
				}
			}
			if(t_veritces[t_vertexId]==null){
				t_veritces[t_vertexId]=(new c_CalVector).m_CalVector_new();
			}
			if(t_normals[t_vertexId]==null){
				t_normals[t_vertexId]=(new c_CalVector).m_CalVector_new();
			}
			if(t_submesh.p_getCoreSubmesh2().p_getSpringCount()>0 && t_submesh.p_hasInternalData()){
				var t_physicalProperty:c_CalPhysicalProperty=t_vectorPhysicalProperty[t_vertexId];
				if(t_physicalProperty.m_weight==0.0){
					t_veritces[t_vertexId].p_assign3(t_x*m_m_axisFactorX,t_y*m_m_axisFactorY,t_z*m_m_axisFactorZ);
				}
			}else{
				t_veritces[t_vertexId].p_assign3(t_x*m_m_axisFactorX,t_y*m_m_axisFactorY,t_z*m_m_axisFactorZ);
			}
			if(m_m_normalize==true){
				t_nx/=m_m_axisFactorX;
				t_ny/=m_m_axisFactorY;
				t_nz/=m_m_axisFactorZ;
				var t_scale:Number=1.0/Math.sqrt(t_nx*t_nx+t_ny*t_ny+t_nz*t_nz);
				t_normals[t_vertexId].p_assign3(t_nx*t_scale,t_ny*t_scale,t_nz*t_scale);
			}else{
				t_normals[t_vertexId].p_assign3(t_nx,t_ny,t_nz);
			}
		}
		return t_vertexCount;
	}
	public function p_calculateTangentSpacesInternal(t_submesh:c_CalSubmesh,t_mapId:int,t_tangentSpaces:Array):int{
		if(t_mapId<0 || t_mapId>=t_submesh.p_getCoreSubmesh2().p_getVectorVectorTangentSpace().length){
			print("internal error: mapId is out of range");
			return 0;
		}
		if(t_tangentSpaces.length<t_submesh.p_getVertexCount()){
			print("internal error: buffer is not large enough to contain all the tangent space data");
			return 0;
		}
		var t_vectorBone:Array=m_m_model.p_getSkeleton().p_getVectorBone();
		var t_vectorVertex:Array=t_submesh.p_getCoreSubmesh2().p_getVectorVertex();
		var t_vectorTangentSpace:Array=t_submesh.p_getCoreSubmesh2().p_getVectorVectorTangentSpace()[t_mapId];
		var t_vertexCount:int=t_submesh.p_getVertexCount();
		var t_v:c_CalVector=(new c_CalVector).m_CalVector_new();
		for(var t_vertexId:int=0;t_vertexId<=t_vertexCount-1;t_vertexId=t_vertexId+1){
			var t_tangentSpace:c_CalTangentSpace=t_vectorTangentSpace[t_vertexId];
			var t_vertex:c_CalVertex=t_vectorVertex[t_vertexId];
			var t_tx:Number=.0;
			var t_ty:Number=.0;
			var t_tz:Number=.0;
			t_tx=0.0;
			t_ty=0.0;
			t_tz=0.0;
			var t_influenceCount:int=t_vertex.m_vectorInfluence.length;
			for(var t_influenceId:int=0;t_influenceId<=t_influenceCount-1;t_influenceId=t_influenceId+1){
				var t_influence:c_CalInfluence=t_vertex.m_vectorInfluence[t_influenceId];
				var t_bone:c_CalBone=t_vectorBone[t_influence.m_boneId];
				t_v.p_assign4(t_tangentSpace.m_tangent);
				t_v.p_multMatrixLocal(t_bone.p_getTransformMatrix());
				t_tx+=t_influence.m_weight*t_v.m_x;
				t_ty+=t_influence.m_weight*t_v.m_y;
				t_tz+=t_influence.m_weight*t_v.m_z;
			}
			if(t_tangentSpaces[t_vertexId]==null){
				t_tangentSpaces[t_vertexId]=(new c_CalTangentSpace).m_CalTangentSpace_new();
			}
			if(m_m_normalize==true){
				t_tx/=m_m_axisFactorX;
				t_ty/=m_m_axisFactorY;
				t_tz/=m_m_axisFactorZ;
				var t_scale:Number=1.0/Math.sqrt(t_tx*t_tx+t_ty*t_ty+t_tz*t_tz);
				t_tangentSpaces[t_vertexId].m_tangent.p_assign3(t_tx*t_scale,t_ty*t_scale,t_tz*t_scale);
			}else{
				t_tangentSpaces[t_vertexId].m_tangent.p_assign3(t_tx,t_ty,t_tz);
			}
			t_tangentSpaces[t_vertexId].m_crossFactor=t_tangentSpace.m_crossFactor;
		}
		return t_vertexCount;
	}
	public function p_update2():void{
		var t_vectorMesh:Array=m_m_model.p_getVectorMesh();
		for(var t_meshId:int=0;t_meshId<=t_vectorMesh.length-1;t_meshId=t_meshId+1){
			var t_vectorSubmesh:Array=t_vectorMesh[t_meshId].p_getVectorSubmesh();
			for(var t_submeshId:int=0;t_submeshId<=t_vectorSubmesh.length-1;t_submeshId=t_submeshId+1){
				var t_submesh:c_CalSubmesh=t_vectorSubmesh[t_submeshId];
				if(t_submesh.p_hasInternalData()==true){
					var t_vectorVertex:Array=t_submesh.p_getVectorVertex();
					var t_vectorNormal:Array=t_submesh.p_getVectorNormal();
					this.p_calculateVerticesAndNormalsInternal(t_submesh,t_vectorVertex,t_vectorNormal);
					var t_vectorTangentSpaceCount:int=t_submesh.p_getVectorVectorTangentSpace().length;
					for(var t_mapId:int=0;t_mapId<=t_vectorTangentSpaceCount-1;t_mapId=t_mapId+1){
						if(t_submesh.p_isTangentsEnabled(t_mapId)==true){
							var t_vectorTangentSpace:Array=t_submesh.p_getVectorVectorTangentSpace()[t_mapId];
							this.p_calculateTangentSpacesInternal(t_submesh,t_mapId,t_vectorTangentSpace);
						}
					}
				}
			}
		}
	}
	public function p_calculateVerticesNormalsAndTexCoords(t_submesh:c_CalSubmesh,t_vertexBuffer:Array,t_numTexCoords:int):int{
		if(t_numTexCoords<0){
			t_numTexCoords=0;
		}
		var t_vectorBone:Array=m_m_model.p_getSkeleton().p_getVectorBone();
		var t_vectorVertex:Array=t_submesh.p_getCoreSubmesh2().p_getVectorVertex();
		var t_vectorvectorTextureCoordinate:Array=t_submesh.p_getCoreSubmesh2().p_getVectorVectorTextureCoordinate();
		var t_textureCoordinateCount:int=t_vectorvectorTextureCoordinate.length;
		if(t_numTexCoords<0 || t_numTexCoords>t_textureCoordinateCount){
			if(t_textureCoordinateCount!=0){
				return -1;
			}
		}
		var t_vectorPhysicalProperty:Array=t_submesh.p_getCoreSubmesh2().p_getVectorPhysicalProperty();
		var t_vertexCount:int=t_submesh.p_getVertexCount();
		var t_vectorSubMorphTarget:Array=t_submesh.p_getCoreSubmesh2().p_getVectorCoreSubMorphTarget();
		var t_baseWeight:Number=t_submesh.p_getBaseWeight();
		var t_morphTargetCount:int=t_submesh.p_getMorphTargetWeightCount();
		var t_vi:int=0;
		var t_position:c_CalVector=(new c_CalVector).m_CalVector_new();
		var t_normal:c_CalVector=(new c_CalVector).m_CalVector_new();
		for(var t_vertexId:int=0;t_vertexId<=t_vertexCount-1;t_vertexId=t_vertexId+1){
			var t_vertex:c_CalVertex=t_vectorVertex[t_vertexId];
			t_position.p_assign3(0.0,0.0,0.0);
			t_normal.p_assign3(0.0,0.0,0.0);
			if(t_baseWeight==1.0){
				t_position.m_x=t_vertex.m_position.m_x;
				t_position.m_y=t_vertex.m_position.m_y;
				t_position.m_z=t_vertex.m_position.m_z;
				t_normal.m_x=t_vertex.m_normal.m_x;
				t_normal.m_y=t_vertex.m_normal.m_y;
				t_normal.m_z=t_vertex.m_normal.m_z;
			}else{
				t_position.m_x=t_baseWeight*t_vertex.m_position.m_x;
				t_position.m_y=t_baseWeight*t_vertex.m_position.m_y;
				t_position.m_z=t_baseWeight*t_vertex.m_position.m_z;
				t_normal.m_x=t_baseWeight*t_vertex.m_normal.m_x;
				t_normal.m_y=t_baseWeight*t_vertex.m_normal.m_y;
				t_normal.m_z=t_baseWeight*t_vertex.m_normal.m_z;
				for(var t_morphTargetId:int=0;t_morphTargetId<=t_morphTargetCount-1;t_morphTargetId=t_morphTargetId+1){
					var t_blendVertex:c_CalBlendVertex=t_vectorSubMorphTarget[t_morphTargetId].p_getVectorBlendVertex()[t_vertexId];
					var t_currentWeight:Number=t_submesh.p_getMorphTargetWeight(t_morphTargetId);
					t_position.m_x+=t_currentWeight*t_blendVertex.m_position.m_x;
					t_position.m_y+=t_currentWeight*t_blendVertex.m_position.m_y;
					t_position.m_z+=t_currentWeight*t_blendVertex.m_position.m_z;
					t_normal.m_x+=t_currentWeight*t_blendVertex.m_normal.m_x;
					t_normal.m_y+=t_currentWeight*t_blendVertex.m_normal.m_y;
					t_normal.m_z+=t_currentWeight*t_blendVertex.m_normal.m_z;
				}
			}
			var t_x:Number=.0;
			var t_y:Number=.0;
			var t_z:Number=.0;
			t_x=0.0;
			t_y=0.0;
			t_z=0.0;
			var t_nx:Number=.0;
			var t_ny:Number=.0;
			var t_nz:Number=.0;
			t_nx=0.0;
			t_ny=0.0;
			t_nz=0.0;
			var t_influenceCount:int=t_vertex.m_vectorInfluence.length;
			if(t_influenceCount==0){
				t_x=t_position.m_x;
				t_y=t_position.m_y;
				t_z=t_position.m_z;
				t_nx=t_normal.m_x;
				t_ny=t_normal.m_y;
				t_nz=t_normal.m_z;
			}else{
				for(var t_influenceId:int=0;t_influenceId<=t_influenceCount-1;t_influenceId=t_influenceId+1){
					var t_influence:c_CalInfluence=t_vertex.m_vectorInfluence[t_influenceId];
					var t_bone:c_CalBone=t_vectorBone[t_influence.m_boneId];
					var t_v:c_CalVector=(new c_CalVector).m_CalVector_new2(t_position);
					t_v.p_multMatrixLocal(t_bone.p_getTransformMatrix());
					t_v.p_addLocal(t_bone.p_getTranslationBoneSpace());
					t_x+=t_influence.m_weight*t_v.m_x;
					t_y+=t_influence.m_weight*t_v.m_y;
					t_z+=t_influence.m_weight*t_v.m_z;
					var t_n:c_CalVector=(new c_CalVector).m_CalVector_new2(t_normal);
					t_n.p_multMatrixLocal(t_bone.p_getTransformMatrix());
					t_nx+=t_influence.m_weight*t_n.m_x;
					t_ny+=t_influence.m_weight*t_n.m_y;
					t_nz+=t_influence.m_weight*t_n.m_z;
				}
			}
			if(t_submesh.p_getCoreSubmesh2().p_getSpringCount()>0 && t_submesh.p_hasInternalData()==true){
				var t_physicalProperty:c_CalPhysicalProperty=t_vectorPhysicalProperty[t_vertexId];
				if(t_physicalProperty.m_weight==0.0){
					t_vertexBuffer[t_vi]=t_x*m_m_axisFactorX;
					t_vertexBuffer[t_vi+1]=t_y*m_m_axisFactorY;
					t_vertexBuffer[t_vi+2]=t_z*m_m_axisFactorZ;
				}
			}else{
				t_vertexBuffer[t_vi]=t_x*m_m_axisFactorX;
				t_vertexBuffer[t_vi+1]=t_y*m_m_axisFactorY;
				t_vertexBuffer[t_vi+2]=t_z*m_m_axisFactorZ;
			}
			if(m_m_normalize==true){
				t_nx/=m_m_axisFactorX;
				t_ny/=m_m_axisFactorY;
				t_nz/=m_m_axisFactorZ;
				var t_scale:Number=1.0/Math.sqrt(t_nx*t_nx+t_ny*t_ny+t_nz*t_nz);
				t_vertexBuffer[t_vi+3]=t_nx*t_scale;
				t_vertexBuffer[t_vi+4]=t_ny*t_scale;
				t_vertexBuffer[t_vi+5]=t_nz*t_scale;
			}else{
				t_vertexBuffer[t_vi+3]=t_nx;
				t_vertexBuffer[t_vi+4]=t_ny;
				t_vertexBuffer[t_vi+5]=t_nz;
			}
			t_vi=t_vi+6;
			if(t_textureCoordinateCount==0){
				t_vi=t_vi+t_numTexCoords*2;
			}else{
				for(var t_mapId:int=0;t_mapId<=t_numTexCoords-1;t_mapId=t_mapId+1){
					var t_textureCoord:c_CalTextureCoordinate=t_vectorvectorTextureCoordinate[t_mapId][t_vertexId];
					t_vertexBuffer[t_vi]=t_textureCoord.m_u;
					t_vertexBuffer[t_vi+1]=t_textureCoord.m_v;
					t_vi=t_vi+2;
				}
			}
		}
		return t_vertexCount;
	}
}
class c_CalSpringSystem extends Object{
	internal var m_m_model:c_CalModel=null;
	internal var m_m_gravity:c_CalVector=null;
	internal var m_m_force:c_CalVector=null;
	internal var m_m_collision:Boolean=false;
	public function m_CalSpringSystem_new():c_CalSpringSystem{
		m_m_model=null;
		m_m_gravity=(new c_CalVector).m_CalVector_new();
		m_m_force=(new c_CalVector).m_CalVector_new();
		m_m_collision=false;
		return this;
	}
	public function m_CalSpringSystem_new2(t_model:c_CalModel):c_CalSpringSystem{
		m_m_model=t_model;
		m_m_gravity=(new c_CalVector).m_CalVector_new3(0.0,0.0,-98.1);
		m_m_force=(new c_CalVector).m_CalVector_new3(0.0,0.5,0.0);
		m_m_collision=false;
		return this;
	}
	public function p_calculateForces(t_submesh:c_CalSubmesh,t_deltaTime:Number):void{
		var t_vectorVertex:Array=t_submesh.p_getVectorVertex();
		var t_vectorPhysicalProperty:Array=t_submesh.p_getVectorPhysicalProperty();
		var t_vectorCorePhysicalProperty:Array=t_submesh.p_getCoreSubmesh2().p_getVectorPhysicalProperty();
		for(var t_vertexId:int=0;t_vertexId<=t_vectorVertex.length-1;t_vertexId=t_vertexId+1){
			var t_physicalProperty:c_CalPhysicalProperty=t_vectorPhysicalProperty[t_vertexId];
			var t_corePhysicalProperty:c_CalPhysicalProperty=t_vectorCorePhysicalProperty[t_vertexId];
			if(t_corePhysicalProperty.m_weight>0.0){
				t_physicalProperty.m_force.p_assign4(m_m_gravity);
				t_physicalProperty.m_force.p_multScalarLocal(t_corePhysicalProperty.m_weight);
				t_physicalProperty.m_force.p_addLocal(m_m_force);
			}
		}
	}
	public function p_calculateVertices2(t_submesh:c_CalSubmesh,t_deltaTime:Number):void{
		var t_vectorVertex:Array=t_submesh.p_getVectorVertex();
		var t_vectorPhysicalProperty:Array=t_submesh.p_getVectorPhysicalProperty();
		var t_vectorCorePhysicalProperty:Array=t_submesh.p_getCoreSubmesh2().p_getVectorPhysicalProperty();
		for(var t_vertexId:int=0;t_vertexId<=t_vectorVertex.length-1;t_vertexId=t_vertexId+1){
			var t_vertex:c_CalVector=t_vectorVertex[t_vertexId];
			var t_physicalProperty:c_CalPhysicalProperty=t_vectorPhysicalProperty[t_vertexId];
			var t_corePhysicalProperty:c_CalPhysicalProperty=t_vectorCorePhysicalProperty[t_vertexId];
			var t_position:c_CalVector=(new c_CalVector).m_CalVector_new2(t_physicalProperty.m_position);
			if(t_corePhysicalProperty.m_weight>0.0){
				t_physicalProperty.m_position.p_addLocal(bb_math_vectorSub(t_position,t_physicalProperty.m_positionOld).p_multScalarLocal(0.99).p_addLocal(bb_math_vectorScalarMult(t_physicalProperty.m_force,t_deltaTime*t_deltaTime/t_corePhysicalProperty.m_weight)));
				var t_skeleton:c_CalSkeleton=m_m_model.p_getSkeleton();
				if(m_m_collision==true){
					var t_vectorBone:Array=t_skeleton.p_getVectorBone();
					for(var t_boneId:int=0;t_boneId<=t_vectorBone.length-1;t_boneId=t_boneId+1){
						var t_p:c_CalBoundingBox=t_vectorBone[t_boneId].p_getBoundingBox();
						var t_isIn:Boolean=true;
						var t_min:int=7696;
						var t_index:int=-1;
						for(var t_faceId:int=0;t_faceId<=5;t_faceId=t_faceId+1){
							if(t_p.m_plane[t_faceId].p_eval(t_physicalProperty.m_position)<=0.0){
								t_isIn=false;
							}else{
								var t_dist:Number=t_p.m_plane[t_faceId].p_dist(t_physicalProperty.m_position);
								if(t_dist<(t_min)){
									t_index=t_faceId;
									t_min=((t_dist)|0);
								}
							}
						}
						if(t_isIn==true && t_index!=-1){
							var t_normal:c_CalVector=(new c_CalVector).m_CalVector_new3(t_p.m_plane[t_index].m_a,t_p.m_plane[t_index].m_b,t_p.m_plane[t_index].m_c);
							t_normal.p_normalize();
							t_physicalProperty.m_position.p_subLocal(bb_math_vectorScalarMult(t_normal,(t_min)));
						}
						t_isIn=true;
						for(var t_faceId2:int=0;t_faceId2<=5;t_faceId2=t_faceId2+1){
							if(t_p.m_plane[t_faceId2].p_eval(t_physicalProperty.m_position)<0.0){
								t_isIn=false;
							}
						}
						if(t_isIn==true){
							t_physicalProperty.m_position.p_assign4(t_vectorVertex[t_vertexId]);
						}
					}
				}
			}else{
				t_physicalProperty.m_position.p_assign4(t_vectorVertex[t_vertexId]);
			}
			t_physicalProperty.m_positionOld.p_assign4(t_position);
			t_vertex.p_assign4(t_physicalProperty.m_position);
			t_physicalProperty.m_force.p_clear();
		}
		var t_vectorSpring:Array=t_submesh.p_getCoreSubmesh2().p_getVectorSpring();
		var t_TOTAL_ITERATION_COUNT:int=2;
		for(var t_iterationCount:int=0;t_iterationCount<=t_TOTAL_ITERATION_COUNT-1;t_iterationCount=t_iterationCount+1){
			for(var t_springId:int=0;t_springId<=t_vectorSpring.length-1;t_springId=t_springId+1){
				var t_spring:c_CalSpring=t_vectorSpring[t_springId];
				var t_distance:c_CalVector=bb_math_vectorSub(t_vectorVertex[t_spring.m_vertexId[1]],t_vectorVertex[t_spring.m_vertexId[0]]);
				var t_Length:Number=t_distance.p_length();
				if(t_Length>0.0){
					var t_factor:Array=new_number_array(2);
					t_factor[0]=(t_Length-t_spring.m_idleLength)/t_Length;
					t_factor[1]=t_factor[0];
					if(t_vectorCorePhysicalProperty[t_spring.m_vertexId[0]].m_weight>0.0){
						t_factor[0]=t_factor[0]/2.0;
						t_factor[1]=t_factor[1]/2.0;
					}else{
						t_factor[0]=0.0;
					}
					if(t_vectorCorePhysicalProperty[t_spring.m_vertexId[1]].m_weight<=0.0){
						t_factor[0]=t_factor[0]*2.0;
						t_factor[1]=0.0;
					}
					t_vectorVertex[t_spring.m_vertexId[0]].p_addLocal(bb_math_vectorScalarMult(t_distance,t_factor[0]));
					t_vectorPhysicalProperty[t_spring.m_vertexId[0]].m_position.p_assign4(t_vectorVertex[t_spring.m_vertexId[0]]);
					t_vectorVertex[t_spring.m_vertexId[1]].p_subLocal(bb_math_vectorScalarMult(t_distance,t_factor[1]));
					t_vectorPhysicalProperty[t_spring.m_vertexId[1]].m_position.p_assign4(t_vectorVertex[t_spring.m_vertexId[1]]);
				}
			}
		}
	}
	public function p_update(t_deltaTime:Number):void{
		var t_vectorMesh:Array=m_m_model.p_getVectorMesh();
		for(var t_meshId:int=0;t_meshId<=t_vectorMesh.length-1;t_meshId=t_meshId+1){
			var t_vectorSubmesh:Array=t_vectorMesh[t_meshId].p_getVectorSubmesh();
			for(var t_submeshId:int=0;t_submeshId<=t_vectorSubmesh.length-1;t_submeshId=t_submeshId+1){
				var t_submesh:c_CalSubmesh=t_vectorSubmesh[t_submeshId];
				if(t_submesh.p_getCoreSubmesh2().p_getSpringCount()>0 && t_submesh.p_hasInternalData()){
					this.p_calculateForces(t_submesh,t_deltaTime);
					this.p_calculateVertices2(t_submesh,t_deltaTime);
				}
			}
		}
	}
}
class c_CalRenderer extends Object{
	internal var m_m_model:c_CalModel=null;
	internal var m_m_selectedSubmesh:c_CalSubmesh=null;
	public function m_CalRenderer_new():c_CalRenderer{
		m_m_model=null;
		m_m_selectedSubmesh=null;
		return this;
	}
	public function m_CalRenderer_new2(t_model:c_CalModel):c_CalRenderer{
		m_m_model=t_model;
		return this;
	}
	public function m_CalRenderer_new3(t_renderer:c_CalRenderer):c_CalRenderer{
		m_m_model=t_renderer.m_m_model;
		m_m_selectedSubmesh=t_renderer.m_m_selectedSubmesh;
		return this;
	}
	public function p_beginRendering():Boolean{
		var t_vectorMesh:Array=m_m_model.p_getVectorMesh();
		if(t_vectorMesh.length==0){
			return false;
		}
		m_m_selectedSubmesh=t_vectorMesh[0].p_getSubmesh(0);
		if(m_m_selectedSubmesh==null){
			return false;
		}
		return true;
	}
	public function p_getMeshCount():int{
		var t_vectorMesh:Array=m_m_model.p_getVectorMesh();
		return t_vectorMesh.length;
	}
	public function p_getSubmeshCount(t_meshId:int):int{
		var t_vectorMesh:Array=m_m_model.p_getVectorMesh();
		if(t_meshId<0 || t_meshId>=t_vectorMesh.length){
			print("Invalid Mesh ID");
			return 0;
		}
		return t_vectorMesh[t_meshId].p_getSubmeshCount2();
	}
	public function p_selectMeshSubmesh(t_meshId:int,t_submeshId:int):Boolean{
		var t_vectorMesh:Array=m_m_model.p_getVectorMesh();
		if(t_meshId<0 || t_meshId>=t_vectorMesh.length){
			print("Invalid Mesh ID");
			return false;
		}
		m_m_selectedSubmesh=t_vectorMesh[t_meshId].p_getSubmesh(t_submeshId);
		if(m_m_selectedSubmesh==null){
			return false;
		}
		return true;
	}
	public function p_getVertexCount():int{
		return m_m_selectedSubmesh.p_getVertexCount();
	}
	public function p_getFaceCount():int{
		return m_m_selectedSubmesh.p_getFaceCount();
	}
	public function p_getVertices(t_vertexBuffer:Array,t_stride:int):int{
		if(m_m_selectedSubmesh.p_hasInternalData()==true){
			var t_vectorVertex:Array=m_m_selectedSubmesh.p_getVectorVertex();
			var t_vertexCount:int=m_m_selectedSubmesh.p_getVertexCount();
			if(t_stride<=0){
				t_stride=3;
			}
			var t_j:int=0;
			for(var t_i:int=0;t_i<=t_vertexCount-1;t_i=t_i+1){
				var t_vertex:c_CalVector=t_vectorVertex[t_i];
				t_vertexBuffer[t_j]=t_vertex.m_x;
				t_vertexBuffer[t_j+1]=t_vertex.m_y;
				t_vertexBuffer[t_j+2]=t_vertex.m_z;
				t_j+=t_stride;
			}
			return t_vertexCount;
		}
		return m_m_model.p_getPhysique().p_calculateVertices(m_m_selectedSubmesh,t_vertexBuffer,t_stride);
	}
	public function p_getFaces(t_faceBuffer:Array):int{
		return m_m_selectedSubmesh.p_getFaces(t_faceBuffer);
	}
	public function p_endRendering():void{
		m_m_selectedSubmesh=null;
	}
	public function p_getVerticesNormalsAndTexCoords(t_vertexBuffer:Array,t_numTexCoords:int):int{
		if(m_m_selectedSubmesh.p_hasInternalData()==true){
			var t_vectorVertex:Array=m_m_selectedSubmesh.p_getVectorVertex();
			var t_vectorNormal:Array=m_m_selectedSubmesh.p_getVectorNormal();
			var t_vectorvectorTextureCoordinate:Array=m_m_selectedSubmesh.p_getCoreSubmesh2().p_getVectorVectorTextureCoordinate();
			var t_textureCoordinateCount:int=t_vectorvectorTextureCoordinate.length;
			if(t_numTexCoords<0){
				t_numTexCoords=1;
			}
			if(t_numTexCoords<0 || t_numTexCoords>t_textureCoordinateCount){
				if(t_textureCoordinateCount!=0){
					print("Invalid Texture Coord Count");
					return -1;
				}
			}
			var t_vertexCount:int=m_m_selectedSubmesh.p_getVertexCount();
			if(t_textureCoordinateCount==0){
				var t_vi:int=0;
				for(var t_vertexId:int=0;t_vertexId<=t_vertexCount-1;t_vertexId=t_vertexId+1){
					var t_vertex:c_CalVector=t_vectorVertex[t_vertexId];
					var t_normal:c_CalVector=t_vectorNormal[t_vertexId];
					t_vertexBuffer[t_vi]=t_vertex.m_x;
					t_vertexBuffer[t_vi+1]=t_vertex.m_y;
					t_vertexBuffer[t_vi+2]=t_vertex.m_z;
					t_vertexBuffer[t_vi+3]=t_normal.m_x;
					t_vertexBuffer[t_vi+4]=t_normal.m_y;
					t_vertexBuffer[t_vi+5]=t_normal.m_z;
					t_vi+=6+t_numTexCoords*2;
				}
			}else{
				if(t_numTexCoords==1){
					var t_vi2:int=0;
					for(var t_vertexId2:int=0;t_vertexId2<=t_vertexCount-1;t_vertexId2=t_vertexId2+1){
						var t_vertex2:c_CalVector=t_vectorVertex[t_vertexId2];
						var t_normal2:c_CalVector=t_vectorNormal[t_vertexId2];
						var t_texCoord:c_CalTextureCoordinate=t_vectorvectorTextureCoordinate[0][t_vertexId2];
						t_vertexBuffer[t_vi2]=t_vertex2.m_x;
						t_vertexBuffer[t_vi2+1]=t_vertex2.m_y;
						t_vertexBuffer[t_vi2+2]=t_vertex2.m_z;
						t_vertexBuffer[t_vi2+3]=t_normal2.m_x;
						t_vertexBuffer[t_vi2+4]=t_normal2.m_y;
						t_vertexBuffer[t_vi2+5]=t_normal2.m_z;
						t_vertexBuffer[t_vi2+6]=t_texCoord.m_u;
						t_vertexBuffer[t_vi2+7]=t_texCoord.m_v;
						t_vi2+=8;
					}
				}else{
					var t_vi3:int=0;
					for(var t_vertexId3:int=0;t_vertexId3<=t_vertexCount-1;t_vertexId3=t_vertexId3+1){
						var t_vertex3:c_CalVector=t_vectorVertex[t_vertexId3];
						var t_normal3:c_CalVector=t_vectorNormal[t_vertexId3];
						t_vertexBuffer[t_vi3]=t_vertex3.m_x;
						t_vertexBuffer[t_vi3+1]=t_vertex3.m_y;
						t_vertexBuffer[t_vi3+2]=t_vertex3.m_z;
						t_vertexBuffer[t_vi3+3]=t_normal3.m_x;
						t_vertexBuffer[t_vi3+4]=t_normal3.m_y;
						t_vertexBuffer[t_vi3+5]=t_normal3.m_z;
						t_vi3+=6;
						for(var t_mapId:int=0;t_mapId<=t_numTexCoords-1;t_mapId=t_mapId+1){
							var t_texCoord2:c_CalTextureCoordinate=t_vectorvectorTextureCoordinate[t_mapId][t_vertexId3];
							t_vertexBuffer[t_vi3]=t_texCoord2.m_u;
							t_vertexBuffer[t_vi3+1]=t_texCoord2.m_v;
							t_vi3+=2;
						}
					}
				}
			}
			return t_vertexCount;
		}
		return m_m_model.p_getPhysique().p_calculateVerticesNormalsAndTexCoords(m_m_selectedSubmesh,t_vertexBuffer,t_numTexCoords);
	}
}
class c_CalSubmesh extends Object{
	internal var m_m_coreSubmesh:c_CalCoreSubmesh=null;
	internal var m_m_vectorMorphTargetWeight:Array=[];
	internal var m_m_vectorVertex:Array=[];
	internal var m_m_vectorNormal:Array=[];
	internal var m_m_vectorvectorTangentSpace:Array=[];
	internal var m_m_vectorFace:Array=[];
	internal var m_m_vectorPhysicalProperty:Array=[];
	internal var m_m_vertexCount:int=0;
	internal var m_m_faceCount:int=0;
	internal var m_m_coreMaterialId:int=0;
	internal var m_m_bInternalData:Boolean=false;
	public function m_CalSubmesh_new():c_CalSubmesh{
		m_m_coreSubmesh=null;
		m_m_vectorMorphTargetWeight=new_number_array(0);
		m_m_vectorVertex=new_object_array(0);
		m_m_vectorNormal=new_object_array(0);
		m_m_vectorvectorTangentSpace=new_array_array(0);
		m_m_vectorFace=new_object_array(0);
		m_m_vectorPhysicalProperty=new_object_array(0);
		m_m_vertexCount=0;
		m_m_faceCount=0;
		m_m_coreMaterialId=-1;
		m_m_bInternalData=false;
		return this;
	}
	public function p_setLodLevel(t_lodLevel:Number):void{
		if(t_lodLevel<0.0){
			t_lodLevel=0.0;
		}else{
			if(t_lodLevel>1.0){
				t_lodLevel=1.0;
			}
		}
		var t_lodCount:int=m_m_coreSubmesh.p_getLodCount();
		t_lodCount=((Math.floor((1.0-t_lodLevel)*(t_lodCount)))|0);
		m_m_vertexCount=m_m_coreSubmesh.p_getVertexCount()-t_lodCount;
		var t_vectorFace:Array=m_m_coreSubmesh.p_getVectorFace();
		var t_vectorVertex:Array=m_m_coreSubmesh.p_getVectorVertex();
		m_m_faceCount=t_vectorFace.length;
		for(var t_vertexId:int=t_vectorVertex.length-1;t_vertexId>=m_m_vertexCount;t_vertexId=t_vertexId+-1){
			m_m_faceCount-=t_vectorVertex[t_vertexId].m_faceCollapseCount;
		}
		for(var t_faceId:int=0;t_faceId<=m_m_faceCount-1;t_faceId=t_faceId+1){
			for(var t_vertexId2:int=0;t_vertexId2<=2;t_vertexId2=t_vertexId2+1){
				var t_collapsedVertexId:int=t_vectorFace[t_faceId].m_vertexId[t_vertexId2];
				while(t_collapsedVertexId>=m_m_vertexCount){
					t_collapsedVertexId=t_vectorVertex[t_collapsedVertexId].m_collapseId;
				}
				m_m_vectorFace[t_faceId].m_vertexId[t_vertexId2]=t_collapsedVertexId;
			}
		}
	}
	public function m_CalSubmesh_new2(t_coreSubmesh:c_CalCoreSubmesh):c_CalSubmesh{
		m_m_coreSubmesh=t_coreSubmesh;
		m_m_vectorMorphTargetWeight=new_number_array(t_coreSubmesh.p_getCoreSubMorphTargetCount());
		m_m_vectorVertex=new_object_array(0);
		m_m_vectorNormal=new_object_array(0);
		m_m_vectorvectorTangentSpace=new_array_array(0);
		m_m_vectorFace=new_object_array(t_coreSubmesh.p_getFaceCount());
		m_m_vectorPhysicalProperty=new_object_array(0);
		m_m_vertexCount=0;
		m_m_faceCount=0;
		m_m_coreMaterialId=-1;
		m_m_bInternalData=false;
		for(var t_faceId:int=0;t_faceId<=m_m_vectorFace.length-1;t_faceId=t_faceId+1){
			m_m_vectorFace[t_faceId]=(new c_CalFace).m_CalFace_new();
		}
		this.p_setLodLevel(1.0);
		var t_morphTargetCount:int=t_coreSubmesh.p_getCoreSubMorphTargetCount();
		for(var t_morphTargetId:int=0;t_morphTargetId<=t_morphTargetCount-1;t_morphTargetId=t_morphTargetId+1){
			m_m_vectorMorphTargetWeight[t_morphTargetId]=0.0;
		}
		if(t_coreSubmesh.p_getSpringCount()>0){
			var t_vertexCount:int=t_coreSubmesh.p_getVertexCount();
			m_m_vectorVertex=new_object_array(t_vertexCount);
			m_m_vectorNormal=new_object_array(t_vertexCount);
			m_m_vectorvectorTangentSpace=new_array_array(t_coreSubmesh.p_getVectorVectorTangentSpace().length);
			m_m_vectorPhysicalProperty=new_object_array(t_vertexCount);
			var t_vectorVertex:Array=t_coreSubmesh.p_getVectorVertex();
			for(var t_vertexId:int=0;t_vertexId<=t_vertexCount-1;t_vertexId=t_vertexId+1){
				m_m_vectorVertex[t_vertexId]=(new c_CalVector).m_CalVector_new2(t_vectorVertex[t_vertexId].m_position);
				var t_physicalProperty:c_CalPhysicalProperty=(new c_CalPhysicalProperty).m_CalPhysicalProperty_new();
				t_physicalProperty.m_position.p_assign4(t_vectorVertex[t_vertexId].m_position);
				t_physicalProperty.m_positionOld.p_assign4(t_vectorVertex[t_vertexId].m_position);
				m_m_vectorPhysicalProperty[t_vertexId]=t_physicalProperty;
				m_m_vectorNormal[t_vertexId]=(new c_CalVector).m_CalVector_new2(t_vectorVertex[t_vertexId].m_normal);
			}
			m_m_bInternalData=true;
		}
		return this;
	}
	public function p_getVertexCount():int{
		return m_m_vertexCount;
	}
	public function p_getFaceCount():int{
		return m_m_faceCount;
	}
	public function p_hasInternalData():Boolean{
		return m_m_bInternalData;
	}
	public function p_getVectorVertex():Array{
		return m_m_vectorVertex;
	}
	public function p_getCoreSubmesh2():c_CalCoreSubmesh{
		return m_m_coreSubmesh;
	}
	public function p_getMorphTargetWeightCount():int{
		return m_m_vectorMorphTargetWeight.length;
	}
	public function p_getBaseWeight():Number{
		var t_baseWeight:Number=1.0;
		var t_morphTargetCount:int=this.p_getMorphTargetWeightCount();
		for(var t_morphTargetId:int=0;t_morphTargetId<=t_morphTargetCount-1;t_morphTargetId=t_morphTargetId+1){
			t_baseWeight-=m_m_vectorMorphTargetWeight[t_morphTargetId];
		}
		return t_baseWeight;
	}
	public function p_getMorphTargetWeight(t_blendId:int):Number{
		return m_m_vectorMorphTargetWeight[t_blendId];
	}
	public function p_getFaces(t_faceBuffer:Array):int{
		var t_j:int=0;
		for(var t_i:int=0;t_i<=m_m_faceCount-1;t_i=t_i+1){
			var t_faceVertId:Array=m_m_vectorFace[t_i].m_vertexId;
			t_faceBuffer[t_j]=t_faceVertId[0];
			t_faceBuffer[t_j+1]=t_faceVertId[1];
			t_faceBuffer[t_j+2]=t_faceVertId[2];
			t_j=t_j+3;
		}
		return m_m_faceCount;
	}
	public function p_setMorphTargetWeight(t_blendId:int,t_weight:Number):void{
		m_m_vectorMorphTargetWeight[t_blendId]=t_weight;
	}
	public function p_getVectorNormal():Array{
		return m_m_vectorNormal;
	}
	public function p_getVectorVectorTangentSpace():Array{
		return m_m_vectorvectorTangentSpace;
	}
	public function p_isTangentsEnabled(t_mapId:int):Boolean{
		return m_m_coreSubmesh.p_isTangentsEnabled(t_mapId);
	}
	public function p_getVectorPhysicalProperty():Array{
		return m_m_vectorPhysicalProperty;
	}
}
class c_CalMesh extends Object{
	internal var m_m_coreMesh:c_CalCoreMesh=null;
	public function p_getCoreMesh2():c_CalCoreMesh{
		return m_m_coreMesh;
	}
	internal var m_m_model:c_CalModel=null;
	internal var m_m_vectorSubmesh:Array=[];
	public function m_CalMesh_new():c_CalMesh{
		m_m_model=null;
		m_m_coreMesh=null;
		m_m_vectorSubmesh=new_object_array(0);
		return this;
	}
	public function m_CalMesh_new2(t_coreMesh:c_CalCoreMesh):c_CalMesh{
		m_m_model=null;
		m_m_coreMesh=t_coreMesh;
		m_m_vectorSubmesh=new_object_array(0);
		var t_vectorCoreSubmesh:Array=t_coreMesh.p_getVectorCoreSubmesh();
		var t_submeshCount:int=t_vectorCoreSubmesh.length;
		for(var t_submeshId:int=0;t_submeshId<=t_submeshCount-1;t_submeshId=t_submeshId+1){
			m_m_vectorSubmesh=resize_object_array(m_m_vectorSubmesh,m_m_vectorSubmesh.length+1);
			m_m_vectorSubmesh[m_m_vectorSubmesh.length-1]=(new c_CalSubmesh).m_CalSubmesh_new2(t_vectorCoreSubmesh[t_submeshId]);
		}
		return this;
	}
	public function p_setModel(t_model:c_CalModel):void{
		m_m_model=t_model;
	}
	public function p_getSubmesh(t_submeshId:int):c_CalSubmesh{
		if(t_submeshId<0 || t_submeshId>=m_m_vectorSubmesh.length){
			print("Invalid Submesh ID");
			return null;
		}
		return m_m_vectorSubmesh[t_submeshId];
	}
	public function p_getSubmeshCount2():int{
		return m_m_vectorSubmesh.length;
	}
	public function p_getVectorSubmesh():Array{
		return m_m_vectorSubmesh;
	}
}
class c_CalBone extends Object{
	internal var m_m_coreBone:c_CalCoreBone=null;
	internal var m_m_skeleton:c_CalSkeleton=null;
	internal var m_m_accumulatedWeight:Number=.0;
	internal var m_m_accumulatedWeightAbsolute:Number=.0;
	internal var m_m_translation:c_CalVector=null;
	internal var m_m_rotation:c_CalQuaternion=null;
	internal var m_m_translationAbsolute:c_CalVector=null;
	internal var m_m_rotationAbsolute:c_CalQuaternion=null;
	internal var m_m_translationBoneSpace:c_CalVector=null;
	internal var m_m_rotationBoneSpace:c_CalQuaternion=null;
	internal var m_m_transformMatrix:c_CalMatrix=null;
	internal var m_m_boundingBox:c_CalBoundingBox=null;
	public function m_CalBone_new():c_CalBone{
		m_m_coreBone=null;
		m_m_skeleton=null;
		m_m_accumulatedWeight=0.0;
		m_m_accumulatedWeightAbsolute=0.0;
		m_m_translation=(new c_CalVector).m_CalVector_new();
		m_m_rotation=(new c_CalQuaternion).m_CalQuaternion_new();
		m_m_translationAbsolute=(new c_CalVector).m_CalVector_new();
		m_m_rotationAbsolute=(new c_CalQuaternion).m_CalQuaternion_new();
		m_m_translationBoneSpace=(new c_CalVector).m_CalVector_new();
		m_m_rotationBoneSpace=(new c_CalQuaternion).m_CalQuaternion_new();
		m_m_transformMatrix=(new c_CalMatrix).m_CalMatrix_new();
		m_m_boundingBox=(new c_CalBoundingBox).m_CalBoundingBox_new();
		return this;
	}
	public function p_clearState():void{
		m_m_accumulatedWeight=0.0;
		m_m_accumulatedWeightAbsolute=0.0;
	}
	public function m_CalBone_new2(t_coreBone:c_CalCoreBone):c_CalBone{
		m_m_coreBone=t_coreBone;
		m_m_skeleton=null;
		m_m_accumulatedWeight=0.0;
		m_m_accumulatedWeightAbsolute=0.0;
		m_m_translation=(new c_CalVector).m_CalVector_new();
		m_m_rotation=(new c_CalQuaternion).m_CalQuaternion_new();
		m_m_translationAbsolute=(new c_CalVector).m_CalVector_new();
		m_m_rotationAbsolute=(new c_CalQuaternion).m_CalQuaternion_new();
		m_m_translationBoneSpace=(new c_CalVector).m_CalVector_new();
		m_m_rotationBoneSpace=(new c_CalQuaternion).m_CalQuaternion_new();
		m_m_transformMatrix=(new c_CalMatrix).m_CalMatrix_new();
		m_m_boundingBox=(new c_CalBoundingBox).m_CalBoundingBox_new();
		this.p_clearState();
		return this;
	}
	public function p_setSkeleton(t_skeleton:c_CalSkeleton):void{
		m_m_skeleton=t_skeleton;
	}
	public function p_getTransformMatrix():c_CalMatrix{
		return m_m_transformMatrix;
	}
	public function p_getTranslationBoneSpace():c_CalVector{
		return m_m_translationBoneSpace;
	}
	public function p_blendState(t_weight:Number,t_translation:c_CalVector,t_rotation:c_CalQuaternion):void{
		if(m_m_accumulatedWeightAbsolute==0.0){
			m_m_translationAbsolute.p_assign4(t_translation);
			m_m_rotationAbsolute.p_assign(t_rotation);
			m_m_accumulatedWeightAbsolute=t_weight;
		}else{
			var t_factor:Number=t_weight/(m_m_accumulatedWeightAbsolute+t_weight);
			m_m_translationAbsolute.p_blend2(t_factor,t_translation);
			m_m_rotationAbsolute.p_blend(t_factor,t_rotation);
			m_m_accumulatedWeightAbsolute+=t_weight;
		}
	}
	public function p_lockState():void{
		if(m_m_accumulatedWeightAbsolute>1.0-m_m_accumulatedWeight){
			m_m_accumulatedWeightAbsolute=1.0-m_m_accumulatedWeight;
		}
		if(m_m_accumulatedWeightAbsolute>0.0){
			if(m_m_accumulatedWeight==0.0){
				m_m_translation.p_assign4(m_m_translationAbsolute);
				m_m_rotation.p_assign(m_m_rotationAbsolute);
				m_m_accumulatedWeight=m_m_accumulatedWeightAbsolute;
			}else{
				var t_factor:Number=m_m_accumulatedWeightAbsolute/(m_m_accumulatedWeight+m_m_accumulatedWeightAbsolute);
				m_m_translation.p_blend2(t_factor,m_m_translationAbsolute);
				m_m_rotation.p_blend(t_factor,m_m_rotationAbsolute);
				m_m_accumulatedWeight+=m_m_accumulatedWeightAbsolute;
			}
			m_m_accumulatedWeightAbsolute=0.0;
		}
	}
	public function p_getRotationAbsolute():c_CalQuaternion{
		return m_m_rotationAbsolute;
	}
	public function p_getTranslationAbsolute():c_CalVector{
		return m_m_translationAbsolute;
	}
	public function p_calculateState():void{
		if(m_m_accumulatedWeight==0.0){
			m_m_translation.p_assign4(m_m_coreBone.p_getTranslation());
			m_m_rotation.p_assign(m_m_coreBone.p_getRotation());
		}
		var t_parentId:int=m_m_coreBone.p_getParentId();
		if(t_parentId==-1){
			m_m_translationAbsolute.p_assign4(m_m_translation);
			m_m_rotationAbsolute.p_assign(m_m_rotation);
		}else{
			var t_parent:c_CalBone=m_m_skeleton.p_getBone(t_parentId);
			m_m_translationAbsolute.p_assign4(m_m_translation);
			m_m_translationAbsolute.p_multQuaternionLocal(t_parent.p_getRotationAbsolute());
			m_m_translationAbsolute.p_addLocal(t_parent.p_getTranslationAbsolute());
			m_m_rotationAbsolute.p_assign(m_m_rotation);
			m_m_rotationAbsolute.p_multQuaternionLocal(t_parent.p_getRotationAbsolute());
		}
		m_m_translationBoneSpace.p_assign4(m_m_coreBone.p_getTranslationBoneSpace());
		m_m_translationBoneSpace.p_multQuaternionLocal(m_m_rotationAbsolute);
		m_m_translationBoneSpace.p_addLocal(m_m_translationAbsolute);
		m_m_rotationBoneSpace.p_assign(m_m_coreBone.p_getRotationBoneSpace());
		m_m_rotationBoneSpace.p_multQuaternionLocal(m_m_rotationAbsolute);
		m_m_transformMatrix.p_assign(m_m_rotationBoneSpace);
		var t_listChildId:Array=m_m_coreBone.p_getListChildId();
		for(var t_iChildId:int=0;t_iChildId<=t_listChildId.length-1;t_iChildId=t_iChildId+1){
			m_m_skeleton.p_getBone(t_listChildId[t_iChildId]).p_calculateState();
		}
	}
	public function p_getBoundingBox():c_CalBoundingBox{
		return m_m_boundingBox;
	}
}
class c_CalMatrix extends Object{
	internal var m_dxdx:Number=.0;
	internal var m_dydx:Number=.0;
	internal var m_dzdx:Number=.0;
	internal var m_dxdy:Number=.0;
	internal var m_dydy:Number=.0;
	internal var m_dzdy:Number=.0;
	internal var m_dxdz:Number=.0;
	internal var m_dydz:Number=.0;
	internal var m_dzdz:Number=.0;
	public function m_CalMatrix_new():c_CalMatrix{
		m_dxdx=1.0;
		m_dydx=0.0;
		m_dzdx=0.0;
		m_dxdy=0.0;
		m_dydy=1.0;
		m_dzdy=0.0;
		m_dxdz=0.0;
		m_dydz=0.0;
		m_dzdz=1.0;
		return this;
	}
	public function m_CalMatrix_new2(t_m:c_CalMatrix):c_CalMatrix{
		m_dxdx=1.0;
		m_dydx=0.0;
		m_dzdx=0.0;
		m_dxdy=0.0;
		m_dydy=1.0;
		m_dzdy=0.0;
		m_dxdz=0.0;
		m_dydz=0.0;
		m_dzdz=1.0;
		m_dxdx=t_m.m_dxdx;
		m_dydx=t_m.m_dydx;
		m_dzdx=t_m.m_dzdx;
		m_dxdy=t_m.m_dxdy;
		m_dydy=t_m.m_dydy;
		m_dzdy=t_m.m_dzdy;
		m_dxdz=t_m.m_dxdz;
		m_dydz=t_m.m_dydz;
		m_dzdz=t_m.m_dzdz;
		return this;
	}
	public function p_assign(t_q:c_CalQuaternion):int{
		var t_xx2:Number=t_q.m_x*t_q.m_x*2.0;
		var t_yy2:Number=t_q.m_y*t_q.m_y*2.0;
		var t_zz2:Number=t_q.m_z*t_q.m_z*2.0;
		var t_xy2:Number=t_q.m_x*t_q.m_y*2.0;
		var t_zw2:Number=t_q.m_z*t_q.m_w*2.0;
		var t_xz2:Number=t_q.m_x*t_q.m_z*2.0;
		var t_yw2:Number=t_q.m_y*t_q.m_w*2.0;
		var t_yz2:Number=t_q.m_y*t_q.m_z*2.0;
		var t_xw2:Number=t_q.m_x*t_q.m_w*2.0;
		m_dxdx=1.0-t_yy2-t_zz2;
		m_dxdy=t_xy2+t_zw2;
		m_dxdz=t_xz2-t_yw2;
		m_dydx=t_xy2-t_zw2;
		m_dydy=1.0-t_xx2-t_zz2;
		m_dydz=t_yz2+t_xw2;
		m_dzdx=t_xz2+t_yw2;
		m_dzdy=t_yz2-t_xw2;
		m_dzdz=1.0-t_xx2-t_yy2;
		return 0;
	}
}
class c_Enumerator13 extends Object{
	internal var m__list:c_List9=null;
	internal var m__curr:c_Node11=null;
	public function m_Enumerator_new(t_list:c_List9):c_Enumerator13{
		m__list=t_list;
		m__curr=t_list.m__head.m__succ;
		return this;
	}
	public function m_Enumerator_new2():c_Enumerator13{
		return this;
	}
	public function p_HasNext():Boolean{
		while(m__curr.m__succ.m__pred!=m__curr){
			m__curr=m__curr.m__succ;
		}
		return m__curr!=m__list.m__head;
	}
	public function p_NextObject():c_Cal3dB3dMesh{
		var t_data:c_Cal3dB3dMesh=m__curr.m__data;
		m__curr=m__curr.m__succ;
		return t_data;
	}
}
class c_CalTangentSpace extends Object{
	internal var m_tangent:c_CalVector=null;
	internal var m_crossFactor:Number=.0;
	public function m_CalTangentSpace_new():c_CalTangentSpace{
		m_tangent=(new c_CalVector).m_CalVector_new();
		m_crossFactor=0.0;
		return this;
	}
	public function m_CalTangentSpace_new2(t_t:c_CalVector,t_c:Number):c_CalTangentSpace{
		m_tangent=(new c_CalVector).m_CalVector_new2(t_t);
		m_crossFactor=t_c;
		return this;
	}
	public function m_CalTangentSpace_new3(t_xx:Number,t_yy:Number,t_zz:Number,t_c:Number):c_CalTangentSpace{
		m_tangent=(new c_CalVector).m_CalVector_new3(t_xx,t_yy,t_zz);
		m_crossFactor=t_c;
		return this;
	}
}
class c_CalFace extends Object{
	internal var m_vertexId:Array=new_number_array(3);
	public function m_CalFace_new():c_CalFace{
		m_vertexId[0]=0;
		m_vertexId[1]=0;
		m_vertexId[2]=0;
		return this;
	}
	public function m_CalFace_new2(t_v1:int,t_v2:int,t_v3:int):c_CalFace{
		m_vertexId[0]=t_v1;
		m_vertexId[1]=t_v2;
		m_vertexId[2]=t_v3;
		return this;
	}
	public function m_CalFace_new3(t_f:c_CalFace):c_CalFace{
		m_vertexId[0]=t_f.m_vertexId[0];
		m_vertexId[1]=t_f.m_vertexId[1];
		m_vertexId[2]=t_f.m_vertexId[2];
		return this;
	}
	public function m_CalFace_new4(t_vi:Array):c_CalFace{
		m_vertexId[0]=t_vi[0];
		m_vertexId[1]=t_vi[1];
		m_vertexId[2]=t_vi[2];
		return this;
	}
}
class c_CalPhysicalProperty extends Object{
	internal var m_weight:Number=.0;
	internal var m_position:c_CalVector=null;
	internal var m_positionOld:c_CalVector=null;
	internal var m_force:c_CalVector=null;
	public function m_CalPhysicalProperty_new():c_CalPhysicalProperty{
		m_weight=0.0;
		m_position=(new c_CalVector).m_CalVector_new();
		m_positionOld=(new c_CalVector).m_CalVector_new();
		m_force=(new c_CalVector).m_CalVector_new();
		return this;
	}
	public function m_CalPhysicalProperty_new2(t_w:Number):c_CalPhysicalProperty{
		m_weight=t_w;
		return this;
	}
	public function m_CalPhysicalProperty_new3(t_p:c_CalVector,t_o:c_CalVector,t_f:c_CalVector,t_w:Number):c_CalPhysicalProperty{
		m_weight=t_w;
		m_position=t_p;
		m_positionOld=t_o;
		m_force=t_f;
		return this;
	}
}
class c_CalCoreSubMorphTarget extends Object{
	internal var m_m_vectorBlendVertex:Array=[];
	public function p_getVectorBlendVertex():Array{
		return m_m_vectorBlendVertex;
	}
}
class c_CalBlendVertex extends Object{
	internal var m_position:c_CalVector=null;
	internal var m_normal:c_CalVector=null;
}
class c_NormHelperClass extends Object{
	public function m_NormHelperClass_new():c_NormHelperClass{
		return this;
	}
	internal var m_vec:c_Vector=null;
	internal var m_vert:int=0;
}
class c_Map5 extends Object{
	public function m_Map_new():c_Map5{
		return this;
	}
	internal var m_root:c_Node15=null;
	public function p_Compare4(t_lhs:c_Vector,t_rhs:c_Vector):int{
		return 0;
	}
	public function p_FindNode3(t_key:c_Vector):c_Node15{
		var t_node:c_Node15=m_root;
		while((t_node)!=null){
			var t_cmp:int=this.p_Compare4(t_key,t_node.m_key);
			if(t_cmp>0){
				t_node=t_node.m_right;
			}else{
				if(t_cmp<0){
					t_node=t_node.m_left;
				}else{
					return t_node;
				}
			}
		}
		return t_node;
	}
	public function p_Get3(t_key:c_Vector):c_NormHelperClass{
		var t_node:c_Node15=this.p_FindNode3(t_key);
		if((t_node)!=null){
			return t_node.m_value;
		}
		return null;
	}
	public function p_RotateLeft3(t_node:c_Node15):int{
		var t_child:c_Node15=t_node.m_right;
		t_node.m_right=t_child.m_left;
		if((t_child.m_left)!=null){
			t_child.m_left.m_parent=t_node;
		}
		t_child.m_parent=t_node.m_parent;
		if((t_node.m_parent)!=null){
			if(t_node==t_node.m_parent.m_left){
				t_node.m_parent.m_left=t_child;
			}else{
				t_node.m_parent.m_right=t_child;
			}
		}else{
			m_root=t_child;
		}
		t_child.m_left=t_node;
		t_node.m_parent=t_child;
		return 0;
	}
	public function p_RotateRight3(t_node:c_Node15):int{
		var t_child:c_Node15=t_node.m_left;
		t_node.m_left=t_child.m_right;
		if((t_child.m_right)!=null){
			t_child.m_right.m_parent=t_node;
		}
		t_child.m_parent=t_node.m_parent;
		if((t_node.m_parent)!=null){
			if(t_node==t_node.m_parent.m_right){
				t_node.m_parent.m_right=t_child;
			}else{
				t_node.m_parent.m_left=t_child;
			}
		}else{
			m_root=t_child;
		}
		t_child.m_right=t_node;
		t_node.m_parent=t_child;
		return 0;
	}
	public function p_InsertFixup3(t_node:c_Node15):int{
		while(((t_node.m_parent)!=null) && t_node.m_parent.m_color==-1 && ((t_node.m_parent.m_parent)!=null)){
			if(t_node.m_parent==t_node.m_parent.m_parent.m_left){
				var t_uncle:c_Node15=t_node.m_parent.m_parent.m_right;
				if(((t_uncle)!=null) && t_uncle.m_color==-1){
					t_node.m_parent.m_color=1;
					t_uncle.m_color=1;
					t_uncle.m_parent.m_color=-1;
					t_node=t_uncle.m_parent;
				}else{
					if(t_node==t_node.m_parent.m_right){
						t_node=t_node.m_parent;
						this.p_RotateLeft3(t_node);
					}
					t_node.m_parent.m_color=1;
					t_node.m_parent.m_parent.m_color=-1;
					this.p_RotateRight3(t_node.m_parent.m_parent);
				}
			}else{
				var t_uncle2:c_Node15=t_node.m_parent.m_parent.m_left;
				if(((t_uncle2)!=null) && t_uncle2.m_color==-1){
					t_node.m_parent.m_color=1;
					t_uncle2.m_color=1;
					t_uncle2.m_parent.m_color=-1;
					t_node=t_uncle2.m_parent;
				}else{
					if(t_node==t_node.m_parent.m_left){
						t_node=t_node.m_parent;
						this.p_RotateRight3(t_node);
					}
					t_node.m_parent.m_color=1;
					t_node.m_parent.m_parent.m_color=-1;
					this.p_RotateLeft3(t_node.m_parent.m_parent);
				}
			}
		}
		m_root.m_color=1;
		return 0;
	}
	public function p_Set2(t_key:c_Vector,t_value:c_NormHelperClass):Boolean{
		var t_node:c_Node15=m_root;
		var t_parent:c_Node15=null;
		var t_cmp:int=0;
		while((t_node)!=null){
			t_parent=t_node;
			t_cmp=this.p_Compare4(t_key,t_node.m_key);
			if(t_cmp>0){
				t_node=t_node.m_right;
			}else{
				if(t_cmp<0){
					t_node=t_node.m_left;
				}else{
					t_node.m_value=t_value;
					return false;
				}
			}
		}
		t_node=(new c_Node15).m_Node_new(t_key,t_value,-1,t_parent);
		if((t_parent)!=null){
			if(t_cmp>0){
				t_parent.m_right=t_node;
			}else{
				t_parent.m_left=t_node;
			}
			this.p_InsertFixup3(t_node);
		}else{
			m_root=t_node;
		}
		return true;
	}
}
class c_NormMap extends c_Map5{
	public function m_NormMap_new():c_NormMap{
		super.m_Map_new();
		return this;
	}
	public override function p_Compare4(t_lhs:c_Vector,t_rhs:c_Vector):int{
		if(t_lhs.m_x<t_rhs.m_x){
			return -1;
		}
		if(t_lhs.m_x>t_rhs.m_x){
			return 1;
		}
		if(t_lhs.m_y<t_rhs.m_y){
			return -1;
		}
		if(t_lhs.m_y>t_rhs.m_y){
			return 1;
		}
		if(t_lhs.m_z<t_rhs.m_z){
			return -1;
		}
		return ((t_lhs.m_z>t_rhs.m_z)?1:0);
	}
}
class c_Node15 extends Object{
	internal var m_key:c_Vector=null;
	internal var m_right:c_Node15=null;
	internal var m_left:c_Node15=null;
	internal var m_value:c_NormHelperClass=null;
	internal var m_color:int=0;
	internal var m_parent:c_Node15=null;
	public function m_Node_new(t_key:c_Vector,t_value:c_NormHelperClass,t_color:int,t_parent:c_Node15):c_Node15{
		this.m_key=t_key;
		this.m_value=t_value;
		this.m_color=t_color;
		this.m_parent=t_parent;
		return this;
	}
	public function m_Node_new2():c_Node15{
		return this;
	}
}
class c_CalCoreTrack extends Object{
	internal var m_m_keyframes:Array=[];
	public function p_getCoreKeyframeCount():int{
		return m_m_keyframes.length;
	}
	public function p_getCoreKeyframe(t_index:int):c_CalCoreKeyframe{
		return m_m_keyframes[t_index];
	}
	public function p_addCoreKeyframe(t_coreKeyframe:c_CalCoreKeyframe):Boolean{
		m_m_keyframes=resize_object_array(m_m_keyframes,m_m_keyframes.length+1);
		m_m_keyframes[m_m_keyframes.length-1]=t_coreKeyframe;
		var t_index:int=m_m_keyframes.length-1;
		while(t_index>0 && m_m_keyframes[t_index].p_getTime()<m_m_keyframes[t_index-1].p_getTime()){
			var t_temp:c_CalCoreKeyframe=m_m_keyframes[t_index];
			m_m_keyframes[t_index]=m_m_keyframes[t_index-1];
			m_m_keyframes[t_index-1]=t_temp;
			t_index=t_index-1;
		}
		return true;
	}
	internal var m_m_coreBoneId:int=0;
	public function p_getCoreBoneId2():int{
		return m_m_coreBoneId;
	}
	public function p_getUpperBound(t_time:Number):int{
		var t_lower:int=0;
		var t_upper:int=m_m_keyframes.length-1;
		while(t_lower<t_upper-1){
			var t_middle:int=t_lower+t_upper>>1;
			if(t_time>=m_m_keyframes[t_middle].p_getTime()){
				t_lower=t_middle;
			}else{
				t_upper=t_middle;
			}
		}
		return t_upper;
	}
	public function p_getState2(t_time:Number,t_translation:c_CalVector,t_rotation:c_CalQuaternion):Boolean{
		var t_coreKeyframeIdBefore:int=0;
		var t_coreKeyframeIdAfter:int=0;
		t_coreKeyframeIdAfter=this.p_getUpperBound(t_time);
		if(t_coreKeyframeIdAfter==m_m_keyframes.length){
			t_coreKeyframeIdAfter=t_coreKeyframeIdAfter-1;
			t_rotation.p_assign(m_m_keyframes[t_coreKeyframeIdAfter].p_getRotation());
			t_translation.p_assign4(m_m_keyframes[t_coreKeyframeIdAfter].p_getTranslation());
			return true;
		}
		if(t_coreKeyframeIdAfter==0){
			t_rotation.p_assign(m_m_keyframes[t_coreKeyframeIdAfter].p_getRotation());
			t_translation.p_assign4(m_m_keyframes[t_coreKeyframeIdAfter].p_getTranslation());
			return true;
		}
		t_coreKeyframeIdBefore=t_coreKeyframeIdAfter-1;
		var t_coreKeyframeBefore:c_CalCoreKeyframe=null;
		var t_coreKeyframeAfter:c_CalCoreKeyframe=null;
		t_coreKeyframeBefore=m_m_keyframes[t_coreKeyframeIdBefore];
		t_coreKeyframeAfter=m_m_keyframes[t_coreKeyframeIdAfter];
		var t_blendFactor:Number=(t_time-t_coreKeyframeBefore.p_getTime())/(t_coreKeyframeAfter.p_getTime()-t_coreKeyframeBefore.p_getTime());
		t_translation.p_assign4(t_coreKeyframeBefore.p_getTranslation());
		t_translation.p_blend2(t_blendFactor,t_coreKeyframeAfter.p_getTranslation());
		t_rotation.p_assign(t_coreKeyframeBefore.p_getRotation());
		t_rotation.p_blend(t_blendFactor,t_coreKeyframeAfter.p_getRotation());
		return true;
	}
	public function m_CalCoreTrack_new():c_CalCoreTrack{
		m_m_coreBoneId=-1;
		m_m_keyframes=new_object_array(0);
		return this;
	}
	public function p_setCoreBoneId(t_coreBoneId:int):Boolean{
		if(t_coreBoneId<0){
			return false;
		}
		m_m_coreBoneId=t_coreBoneId;
		return true;
	}
}
class c_CalCoreKeyframe extends Object{
	internal var m_m_time:Number=.0;
	public function p_getTime():Number{
		return m_m_time;
	}
	internal var m_m_translation:c_CalVector=null;
	internal var m_m_rotation:c_CalQuaternion=null;
	public function m_CalCoreKeyframe_new():c_CalCoreKeyframe{
		m_m_time=0.0;
		m_m_translation=(new c_CalVector).m_CalVector_new();
		m_m_rotation=(new c_CalQuaternion).m_CalQuaternion_new();
		return this;
	}
	public function m_CalCoreKeyframe_new2(t_time:Number,t_t:c_CalVector,t_r:c_CalQuaternion):c_CalCoreKeyframe{
		m_m_time=t_time;
		m_m_translation=(new c_CalVector).m_CalVector_new2(t_t);
		m_m_rotation=(new c_CalQuaternion).m_CalQuaternion_new2(t_r);
		return this;
	}
	public function p_getTranslation():c_CalVector{
		return m_m_translation;
	}
	public function p_setTranslation(t_translation:c_CalVector):void{
		m_m_translation.p_assign4(t_translation);
	}
	public function p_getRotation():c_CalQuaternion{
		return m_m_rotation;
	}
	public function p_setRotation(t_rotation:c_CalQuaternion):void{
		m_m_rotation.p_assign(t_rotation);
	}
	public function p_setTime(t_time:Number):void{
		m_m_time=t_time;
	}
}
internal function bb_mixer_addExtraKeyframeForLoopedAnim(t_coreAnimation:c_CalCoreAnimation):void{
	var t_listCoreTrack:Array=t_coreAnimation.p_getListCoreTrack();
	if(t_listCoreTrack.length==0){
		return;
	}
	var t_coreTrackId:int=0;
	if(t_listCoreTrack[t_coreTrackId]==null){
		return;
	}
	var t_lastKeyframe:c_CalCoreKeyframe=t_listCoreTrack[t_coreTrackId].p_getCoreKeyframe(t_listCoreTrack[t_coreTrackId].p_getCoreKeyframeCount()-1);
	if(t_lastKeyframe==null){
		return;
	}
	if(t_lastKeyframe.p_getTime()<t_coreAnimation.p_getDuration()){
		for(t_coreTrackId=0;t_coreTrackId<=t_listCoreTrack.length-1;t_coreTrackId=t_coreTrackId+1){
			var t_coreTrack:c_CalCoreTrack=t_listCoreTrack[t_coreTrackId];
			var t_firstKeyframe:c_CalCoreKeyframe=t_coreTrack.p_getCoreKeyframe(0);
			var t_newKeyframe:c_CalCoreKeyframe=(new c_CalCoreKeyframe).m_CalCoreKeyframe_new();
			t_newKeyframe.p_setTranslation(t_firstKeyframe.p_getTranslation());
			t_newKeyframe.p_setRotation(t_firstKeyframe.p_getRotation());
			t_newKeyframe.p_setTime(t_coreAnimation.p_getDuration());
			t_coreTrack.p_addCoreKeyframe(t_newKeyframe);
		}
	}
}
class c_CalCallbackRecord extends Object{
	internal var m_callback:c_CalAnimationCallback=null;
	internal var m_min_interval:Number=.0;
}
class c_CalAnimationType extends Object{
}
class c_CalAnimationState extends Object{
}
class c_CalAnimationCallback extends c_CalCallbackRecord{
	public function p_AnimationUpdate(t_anim_time:Number,t_model:c_CalModel,t_userData:Object):void{
	}
	public function p_AnimationComplete(t_model:c_CalModel,t_userData:Object):void{
	}
}
internal function bb_animation_Modf(t_a:Number,t_n:Number):Number{
	var t_ret:Number=t_a-t_n*Math.floor(t_a/t_n);
	return t_ret;
}
internal function bb_math_vectorScalarMult(t_v:c_CalVector,t_d:Number):c_CalVector{
	return (new c_CalVector).m_CalVector_new3(t_v.m_x*t_d,t_v.m_y*t_d,t_v.m_z*t_d);
}
internal function bb_math_vectorSub(t_v0:c_CalVector,t_v1:c_CalVector):c_CalVector{
	return (new c_CalVector).m_CalVector_new3(t_v0.m_x-t_v1.m_x,t_v0.m_y-t_v1.m_y,t_v0.m_z-t_v1.m_z);
}
internal function bb_math_vectorSub2(t_v0:c_CalVertex,t_v1:c_CalVertex):c_CalVector{
	return (new c_CalVector).m_CalVector_new3(t_v0.m_position.m_x-t_v1.m_position.m_x,t_v0.m_position.m_y-t_v1.m_position.m_y,t_v0.m_position.m_z-t_v1.m_position.m_z);
}
class c_CalTextureCoordinate extends Object{
	internal var m_u:Number=.0;
	internal var m_v:Number=.0;
	public function m_CalTextureCoordinate_new():c_CalTextureCoordinate{
		m_u=0.0;
		m_v=0.0;
		return this;
	}
	public function m_CalTextureCoordinate_new2(t_uv:c_CalTextureCoordinate):c_CalTextureCoordinate{
		m_u=t_uv.m_u;
		m_v=t_uv.m_v;
		return this;
	}
	public function m_CalTextureCoordinate_new3(t_uu:Number,t_vv:Number):c_CalTextureCoordinate{
		m_u=t_uu;
		m_v=t_vv;
		return this;
	}
}
class c_CalImage extends Object{
	internal var m_finished:Boolean=false;
	public function p_IsFinished():Boolean{
		return m_finished;
	}
	internal var m_pos:int=0;
	internal var m_pixels:Array=[];
	internal var m_posx:int=0;
	internal var m_posy:int=0;
	internal var m_tex:c_TPixmap=null;
	internal var m_w:int=0;
	internal var m_h:int=0;
	internal var m_texture:c_TTexture=null;
	public function p_MakeTexture():c_TTexture{
		print("Create Texture");
		m_texture=c_TTexture.m_CreateTexture(m_w,m_h,9,1,null);
		m_texture.m_pixmap=m_tex;
		return m_texture;
	}
	public function p_Update():void{
		if(m_finished==false){
			for(var t_i:int=0;t_i<=255;t_i=t_i+1){
				if(m_pos<m_pixels.length){
					var t_col:Array=bb_calimage_IntToRGBA(parseInt((m_pixels[m_pos]),10));
					m_tex.p_SetPixel(m_posx,m_posy,t_col[1],t_col[2],t_col[3],255);
					m_posx=m_posx+1;
					if(m_posx>=m_w){
						m_posx=0;
						m_posy=m_posy+1;
					}
					m_pos=m_pos+1;
				}else{
					print("Finished Loading Image");
					this.p_MakeTexture();
					m_finished=true;
					break;
				}
			}
		}
	}
	public function m_CalImage_new():c_CalImage{
		m_w=0;
		m_h=0;
		m_pos=0;
		m_pixels=new_string_array(0);
		m_finished=false;
		m_posx=0;
		m_posy=0;
		return this;
	}
	public function m_CalImage_new2(t_ww:int,t_hh:int,t_pix:Array):c_CalImage{
		m_w=t_ww;
		m_h=t_hh;
		m_pixels=t_pix;
		m_finished=false;
		m_posx=0;
		m_posy=0;
		print("New CalImage W: "+String(m_w)+" H: "+String(m_h)+" pixels: "+String(m_pixels.length));
		m_tex=c_TPixmap.m_CreatePixmap(m_w,m_h,4);
		return this;
	}
}
internal function bb_calimage_IntToRGBA(t_Value:int):Array{
	var t_rgba:Array=new_number_array(4);
	t_rgba[0]=t_Value>>24&255;
	t_rgba[1]=t_Value>>16&255;
	t_rgba[2]=t_Value>>8&255;
	t_rgba[3]=t_Value&255;
	return t_rgba;
}
internal function bb_functions_EntityTexture(t_ent:c_TEntity,t_tex:c_TTexture,t_frame:int,t_index:int):int{
	((t_ent) as c_TMesh).p_EntityTexture(t_tex,t_frame,t_index);
	return 0;
}
var bb_asyncevent__current:c_IAsyncEventSource;
internal function bb_asyncevent_UpdateAsyncEvents():int{
	if((bb_asyncevent__current)!=null){
		return 0;
	}
	var t_i:int=0;
	while(t_i<bb_asyncevent__sources.p_Length2()){
		bb_asyncevent__current=bb_asyncevent__sources.p_Get(t_i);
		bb_asyncevent__current.p_UpdateAsyncEvents();
		if((bb_asyncevent__current)!=null){
			t_i+=1;
		}
	}
	bb_asyncevent__current=null;
	return 0;
}
internal function bb_input_KeyDown(t_key:int):int{
	return ((bb_input_device.p_KeyDown(t_key))?1:0);
}
internal function bb_input_TouchDown(t_index:int):int{
	return ((bb_input_device.p_KeyDown(384+t_index))?1:0);
}
internal function bb_input_TouchX(t_index:int):Number{
	return bb_input_device.p_TouchX(t_index);
}
internal function bb_input_TouchY(t_index:int):Number{
	return bb_input_device.p_TouchY(t_index);
}
class c_TShaderFlash extends c_TShader{
	internal static var m_driver:Driver3D;
	internal static var m_g_id:int;
	internal var m_vertex_assembly:AGALMiniAssembler=null;
	internal var m_vertex_code:ByteArray=null;
	internal var m_fragment_assembly:AGALMiniAssembler=null;
	internal var m_fragment_code:ByteArray=null;
	public override function p_CompileShader(t_source:String,t_type:int):int{
		if(t_source.length<2){
			print("**Shader file not found");
			return 0;
		}
		var t_verbose:Boolean=false;
		var t_result:ByteArray=null;
		if(t_type==1){
			m_vertex_id=m_g_id;
			m_vertex_assembly=(new AGALMiniAssembler(false));
			m_vertex_code=m_vertex_assembly.assemble(Context3DProgramType.VERTEX,t_source,t_verbose);
			t_result=m_vertex_code;
		}
		if(t_type==2){
			m_fragment_id=m_g_id;
			m_fragment_assembly=(new AGALMiniAssembler(false));
			m_fragment_code=m_fragment_assembly.assemble(Context3DProgramType.FRAGMENT,t_source,t_verbose);
			t_result=m_fragment_code;
		}
		var t_ll:int=t_result.length; //();
		if(!((t_result)!=null)){
			print("**Shader Compiler Error");
			if(t_type==1){
				m_vertex_id=0;
			}else{
				m_fragment_id=0;
			}
			return 0;
		}
		m_g_id+=1;
		return 1;
	}
	internal var m_program_set:Program3D=null;
	internal var m_u:c_ShaderUniforms=null;
	public function p_LinkVariables():int{
		return 0;
	}
	public function p_LinkShader():int{
		m_program_set=m_driver.context3d.createProgram();
		try{
			m_program_set.upload(m_vertex_code,m_fragment_code);
		}catch(t_e:Error){
			print(t_e.toString());
			error("");
		}
		try{
			m_driver.context3d.setProgram(m_program_set);
		}catch(t_e2:Error){
			print(t_e2.toString());
			m_vertex_id=0;
			m_fragment_id=0;
			m_shader_id=0;
			print("**Error: Program Link not created.");
			return 0;
		}
		m_active=1;
		m_u=(new c_ShaderUniforms).m_ShaderUniforms_new();
		this.p_LinkVariables();
		return 1;
	}
	public static function m_LoadShaderString(t_vp:String,t_fp:String,t_shader:c_TShaderFlash):c_TShaderFlash{
		var t_fail:int=1;
		if(!((t_shader)!=null)){
			t_shader=(new c_TShaderFlash).m_TShaderFlash_new("","");
		}
		var t_vs:int=t_shader.p_CompileShader(t_vp,1);
		var t_fs:int=t_shader.p_CompileShader(t_fp,2);
		if(((t_vs)!=0) && ((t_fs)!=0)){
			if((t_shader.p_LinkShader())!=0){
				t_fail=0;
			}
		}
		if(!((t_fail)!=0)){
		}else{
			print("**compiler error");
		}
		return t_shader;
	}
	public function m_TShaderFlash_new(t_vp:String,t_fp:String):c_TShaderFlash{
		super.m_TShader_new();
		m_driver=c_FlashMiniB3D.m_driver;
		if(t_vp!="" && t_fp!=""){
			m_LoadShaderString(t_vp,t_fp,this);
			if((m_shader_id)!=0){
				m_active=1;
			}
		}
		return this;
	}
	public override function p_ResetShader():int{
		return 0;
	}
	internal var m_use_base_variables:int=1;
	public override function p_Copy():c_TBrush{
		var t_brush:c_TShaderFlash=(new c_TShaderFlash).m_TShaderFlash_new("","");
		t_brush.m_no_texs=m_no_texs;
		t_brush.m_name=m_name;
		t_brush.m_red=m_red;
		t_brush.m_green=m_green;
		t_brush.m_blue=m_blue;
		t_brush.m_alpha=m_alpha;
		t_brush.m_shine=m_shine;
		t_brush.m_blend=m_blend;
		t_brush.m_fx=m_fx;
		t_brush.m_tex[0]=m_tex[0];
		t_brush.m_tex[1]=m_tex[1];
		t_brush.m_tex[2]=m_tex[2];
		t_brush.m_tex[3]=m_tex[3];
		t_brush.m_tex[4]=m_tex[4];
		t_brush.m_tex[5]=m_tex[5];
		t_brush.m_tex[6]=m_tex[6];
		t_brush.m_tex[7]=m_tex[7];
		t_brush.m_shader_id=m_shader_id;
		t_brush.m_fragment_id=m_fragment_id;
		t_brush.m_vertex_id=m_vertex_id;
		t_brush.m_u=m_u;
		t_brush.m_override=m_override;
		t_brush.m_active=1;
		t_brush.p_LinkVariables();
		t_brush.m_active=m_active;
		t_brush.m_use_base_variables=m_use_base_variables;
		return (t_brush);
	}
}
class c_MultiShader extends c_TShaderFlash{
	internal static var m_init:Boolean;
	internal var m_shader:Array=new_object_array(8);
	public override function p_ResetShader():int{
		m_shader[0]=((new c_FullBrightOneTexShader).m_FullBrightOneTexShader_new("clamp",c_FullBrightOneTexShader.m_VP,c_FullBrightOneTexShader.m_FP));
		m_shader[1]=((new c_FullBrightOneTexShader).m_FullBrightOneTexShader_new("repeat",c_FullBrightOneTexShader.m_VP,c_FullBrightOneTexShader.m_FP));
		m_shader[2]=((new c_OneLightOneTexShader).m_OneLightOneTexShader_new("clamp",c_OneLightOneTexShader.m_VP,c_OneLightOneTexShader.m_FP));
		m_shader[3]=((new c_OneLightOneTexShader).m_OneLightOneTexShader_new("repeat",c_OneLightOneTexShader.m_VP,c_OneLightOneTexShader.m_FP));
		return 0;
	}
	public function m_MultiShader_new():c_MultiShader{
		super.m_TShaderFlash_new("","");
		if(m_init){
			return this;
		}
		m_init=true;
		this.p_ResetShader();
		return this;
	}
	public function p_GetShader(t_i:int):c_TShaderFlash{
		return m_shader[t_i];
	}
}
class c_ShaderUniforms extends Object{
	public function m_ShaderUniforms_new():c_ShaderUniforms{
		return this;
	}
	internal var m_vertcoords:int=0;
	internal var m_normals:int=0;
	internal var m_colors:int=0;
	internal var m_texcoords0:int=0;
	internal var m_texcoords1:int=0;
	internal var m_tex_position:Array=new_number_array(9);
	internal var m_tex_scale:Array=new_number_array(9);
	internal var m_m_matrix:int=0;
	internal var m_n_matrix:int=0;
	internal var m_p_matrix:int=0;
	internal var m_light_matrix:Array=new_number_array(9);
	internal var m_lightflag:int=0;
	internal var m_light_color:Array=new_number_array(9);
	internal var m_light_att:Array=new_number_array(9);
	internal var m_colorflag:int=0;
	internal var m_base_color:int=0;
	internal var m_ambient_color:int=0;
	internal var m_miscflag:int=0;
	internal var m_tex_blend:Array=new_number_array(9);
	internal var m_light_spot:Array=new_number_array(9);
}
class c_OneLightOneTexShader extends c_TShaderFlash{
	internal static var m_VP:String;
	internal static var m_FP:String;
	internal static var m_alphaTest:String;
	public function m_OneLightOneTexShader_new(t_tex_clamp:String,t_vp:String,t_fp:String):c_OneLightOneTexShader{
		super.m_TShaderFlash_new("","");
		t_fp=bb_tshader_flash_StringReplace("TEXTURE_WRAP",t_tex_clamp,t_fp);
		t_fp=bb_tshader_flash_StringReplace("ALPHATEST",m_alphaTest,t_fp);
		c_TShaderFlash.m_driver=c_FlashMiniB3D.m_driver;
		if(t_vp!="" && t_fp!=""){
			c_TShaderFlash.m_LoadShaderString(t_vp,t_fp,(this));
			if((m_shader_id)!=0){
				m_active=1;
			}
		}
		return this;
	}
	public function m_OneLightOneTexShader_new2():c_OneLightOneTexShader{
		super.m_TShaderFlash_new("","");
		return this;
	}
	public override function p_LinkVariables():int{
		m_active=1;
		m_u.m_vertcoords=0;
		m_u.m_texcoords0=2;
		m_u.m_texcoords1=-1;
		m_u.m_normals=3;
		m_u.m_colors=1;
		m_u.m_p_matrix=0;
		m_u.m_m_matrix=4;
		m_u.m_n_matrix=8;
		m_u.m_light_matrix[0]=12;
		m_u.m_base_color=16;
		m_u.m_ambient_color=17;
		m_u.m_light_color[0]=22;
		m_u.m_tex_position[0]=23;
		m_u.m_tex_scale[0]=24;
		m_u.m_tex_blend[0]=1;
		m_u.m_colorflag=18;
		m_u.m_miscflag=25;
		m_u.m_lightflag=26;
		m_u.m_light_att[0]=27;
		m_u.m_light_spot[0]=28;
		return 0;
	}
}
class c_FullBrightOneTexShader extends c_OneLightOneTexShader{
	internal static var m_VP:String;
	internal static var m_FP:String;
	internal static var m_alphaTest:String;
	public function m_FullBrightOneTexShader_new(t_tex_clamp:String,t_vp:String,t_fp:String):c_FullBrightOneTexShader{
		super.m_OneLightOneTexShader_new2();
		t_fp=bb_tshader_flash_StringReplace("TEXTURE_WRAP",t_tex_clamp,t_fp);
		t_fp=bb_tshader_flash_StringReplace("ALPHATEST",m_alphaTest,t_fp);
		c_TShaderFlash.m_driver=c_FlashMiniB3D.m_driver;
		if(t_vp!="" && t_fp!=""){
			c_TShaderFlash.m_LoadShaderString(t_vp,t_fp,(this));
			if((m_shader_id)!=0){
				m_active=1;
			}
		}
		return this;
	}
	public function m_FullBrightOneTexShader_new2():c_FullBrightOneTexShader{
		super.m_OneLightOneTexShader_new2();
		return this;
	}
	public override function p_LinkVariables():int{
		super.p_LinkVariables();
		m_u.m_light_matrix[0]=-1;
		m_u.m_light_color[0]=-1;
		return 0;
	}
}
internal function bb_tshader_flash_StringReplace(t_r:String,t_n:String,t_st:String):String{
	var t_a:Array=t_st.split(t_r);
	if(t_a.length==2){
		t_st=t_a[0]+t_n+t_a[1];
	}else{
		print("**Shader error: string replace");
	}
	return t_st;
}
class c_EffectState extends Object{
	public function m_EffectState_new():c_EffectState{
		return this;
	}
	internal var m_use_full_bright:int=0;
	internal var m_use_vertex_colors:int=0;
	internal var m_use_flatshade:int=0;
	internal var m_use_fog:int=1;
	internal var m_ambient:Array=[1.0,1.0,1.0,1.0];
	internal var m_diffuse:Array=[1.0,1.0,1.0,1.0];
	internal var m_specular:Array=[1.0,1.0,1.0,1.0];
	internal var m_shininess:Array=[100.0];
	internal var m_use_depth_test:int=0;
	internal var m_use_depth_write:int=0;
	internal var m_use_backface_culling:int=0;
	internal var m_use_alpha_test:int=0;
	internal var m_use_perpixellighting:int=0;
	internal var m_red:Number=.0;
	internal var m_green:Number=.0;
	internal var m_blue:Number=.0;
	internal var m_alpha:Number=.0;
	internal var m_shine:Number=.0;
	internal var m_blend:int=0;
	internal var m_fx:int=0;
	internal var m_num_tex:int=0;
	public function p_SetNull():void{
		m_use_full_bright=-1;
		m_use_vertex_colors=-1;
		m_use_flatshade=-1;
		m_use_fog=-1;
		m_ambient=[-1.0,-1.0,-1.0,1.0];
		m_diffuse=[-1.0,-1.0,-1.0,1.0];
		m_specular=[-1.0,-1.0,-1.0,1.0];
		m_shininess=[-1.0];
		m_use_depth_test=-1;
		m_use_depth_write=-1;
		m_use_backface_culling=-1;
		m_use_alpha_test=0;
		m_use_perpixellighting=0;
		m_red=-1.0;
		m_green=-1.0;
		m_blue=-1.0;
		m_alpha=-1.0;
		m_shine=-1.0;
		m_blend=99999;
		m_fx=99999;
		m_num_tex=-1;
	}
	internal var m_tex:Array=[];
	public function p_UpdateEffect(t_surf:c_TSurface,t_ent:c_TEntity,t_cam:c_TCamera):void{
		var t_ambient_red:Number=.0;
		var t_ambient_green:Number=.0;
		var t_ambient_blue:Number=.0;
		m_red=t_ent.m_brush.m_red;
		m_green=t_ent.m_brush.m_green;
		m_blue=t_ent.m_brush.m_blue;
		m_alpha=t_ent.m_brush.m_alpha;
		m_shine=t_ent.m_brush.m_shine;
		m_blend=t_ent.m_brush.m_blend;
		m_fx=t_ent.m_brush.m_fx;
		m_num_tex=t_ent.m_brush.m_no_texs;
		m_tex=t_ent.m_brush.m_tex;
		if((t_surf.m_brush)!=null){
			var t_shine2:Number=0.0;
			m_red=m_red*t_surf.m_brush.m_red;
			m_green=m_green*t_surf.m_brush.m_green;
			m_blue=m_blue*t_surf.m_brush.m_blue;
			m_alpha=m_alpha*t_surf.m_brush.m_alpha;
			t_shine2=t_surf.m_brush.m_shine;
			if(m_shine==0.0){
				m_shine=t_shine2;
			}
			if(m_shine!=0.0 && t_shine2!=0.0){
				m_shine=m_shine*t_shine2;
			}
			if(m_blend==0){
				m_blend=t_surf.m_brush.m_blend;
			}
			m_fx=m_fx|t_surf.m_brush.m_fx;
			if(m_num_tex<t_surf.m_brush.m_no_texs){
				m_num_tex=t_surf.m_brush.m_no_texs;
				m_tex=t_surf.m_brush.m_tex;
			}
		}
		m_alpha=m_alpha-t_ent.m_fade_alpha;
		m_use_depth_test=1;
		m_use_depth_write=1;
		var t_enable_blend:int=0;
		if(t_ent.m_using_alpha==true){
			if(t_ent.m_brush.m_alpha<1.0){
				t_enable_blend=1;
				m_use_depth_write=0;
			}else{
				if(t_surf.m_alpha_enable==true){
					t_enable_blend=1;
					m_use_depth_write=0;
				}else{
					t_enable_blend=0;
					m_use_depth_test=1;
					m_use_depth_write=1;
				}
			}
		}else{
			t_enable_blend=0;
		}
		if(t_enable_blend==0){
			m_blend=-1;
		}
		m_use_vertex_colors=0;
		m_use_flatshade=0;
		m_use_fog=((t_cam.m_fog_mode>0)?1:0);
		if((m_fx&1)!=0){
			t_ambient_red=0.0;
			t_ambient_green=0.0;
			t_ambient_blue=0.0;
			m_use_full_bright=1;
		}else{
			t_ambient_red=c_TLight.m_ambient_red;
			t_ambient_green=c_TLight.m_ambient_green;
			t_ambient_blue=c_TLight.m_ambient_blue;
			m_use_full_bright=0;
		}
		if((m_fx&2)!=0){
			m_use_vertex_colors=1;
			m_red=1.0;
			m_green=1.0;
			m_blue=1.0;
			m_alpha=1.0;
		}
		if((m_fx&4)!=0){
			m_use_flatshade=1;
		}
		if((m_fx&8)!=0){
			m_use_fog=0;
		}
		if((m_fx&16)!=0){
			m_use_backface_culling=0;
		}else{
			m_use_backface_culling=1;
		}
		if((m_fx&64)!=0){
			m_use_depth_test=0;
			m_use_depth_write=0;
		}
		m_use_alpha_test=0;
		var t_tex_alphatest:int=0;
		if(m_num_tex>0){
			for(var t_i:int=0;t_i<=m_num_tex-1;t_i=t_i+1){
				if((m_tex[t_i])!=null){
					t_tex_alphatest|=m_tex[t_i].m_flags&4;
				}
			}
		}
		if((m_fx&128)>0 || t_tex_alphatest>0){
			m_use_alpha_test=1;
			m_use_depth_test=1;
			m_use_depth_write=1;
		}
		if((m_fx&256)!=0){
			m_use_perpixellighting=1;
		}
		m_ambient=[t_ambient_red,t_ambient_green,t_ambient_blue,0.0];
		m_diffuse=[m_red,m_green,m_blue,m_alpha];
		m_specular=[m_shine,m_shine,m_shine,1.0];
		m_shininess=[100.0];
		if((t_cam.m_draw2D)!=0){
			if((m_fx&64)==0){
				m_use_depth_test=0;
				m_use_depth_write=0;
			}
			m_use_fog=0;
			m_use_full_bright=1;
		}
	}
	public function p_Overwrite2(t_e:c_EffectState):void{
		m_use_full_bright=t_e.m_use_full_bright;
		m_use_vertex_colors=t_e.m_use_vertex_colors;
		m_use_flatshade=t_e.m_use_flatshade;
		m_use_fog=t_e.m_use_fog;
		m_ambient=[t_e.m_ambient[0],t_e.m_ambient[1],t_e.m_ambient[2],t_e.m_ambient[3]];
		m_diffuse=[t_e.m_diffuse[0],t_e.m_diffuse[1],t_e.m_diffuse[2],t_e.m_diffuse[3]];
		m_specular=[t_e.m_specular[0],t_e.m_specular[1],t_e.m_specular[2],t_e.m_specular[3]];
		m_shininess=[t_e.m_shininess[0]];
		m_use_depth_test=t_e.m_use_depth_test;
		m_use_depth_write=t_e.m_use_depth_write;
		m_use_backface_culling=t_e.m_use_backface_culling;
		m_red=t_e.m_red;
		m_green=t_e.m_green;
		m_blue=t_e.m_blue;
		m_alpha=t_e.m_alpha;
		m_shine=t_e.m_shine;
		m_blend=t_e.m_blend;
		m_fx=t_e.m_fx;
		m_use_alpha_test=t_e.m_use_alpha_test;
		m_use_perpixellighting=t_e.m_use_perpixellighting;
		m_num_tex=t_e.m_num_tex;
	}
}
class c_SurfaceAlphaList extends c_List2{
	public function m_SurfaceAlphaList_new():c_SurfaceAlphaList{
		super.m_List_new();
		return this;
	}
}
class c_FloatBuffer extends Object{
	internal var m_buf:c_DataBuffer=null;
}
class c_TVertexAnim extends c_FloatBuffer{
}
class c_ArrayIntMap extends Object{
	internal var m_data:Array=[];
	internal var m_length:int=0;
	public function m_ArrayIntMap_new():c_ArrayIntMap{
		m_data=new_object_array(32);
		m_length=31;
		return this;
	}
	public function p_Set3(t_id:int,t_obj:VertexBuffer3D):void{
		while(t_id>=m_length){
			m_length=m_length+32;
			m_data=resize_object_array(m_data,m_length+1);
		}
		m_data[t_id]=t_obj;
	}
	public function p_Get(t_id:int):VertexBuffer3D{
		if(t_id<m_length){
			return m_data[t_id];
		}
		return null;
	}
}
class c_ArrayIntMap2 extends Object{
	internal var m_data:Array=[];
	internal var m_length:int=0;
	public function m_ArrayIntMap_new():c_ArrayIntMap2{
		m_data=new_object_array(32);
		m_length=31;
		return this;
	}
	public function p_Set4(t_id:int,t_obj:IndexBuffer3D):void{
		while(t_id>=m_length){
			m_length=m_length+32;
			m_data=resize_object_array(m_data,m_length+1);
		}
		m_data[t_id]=t_obj;
	}
	public function p_Get(t_id:int):IndexBuffer3D{
		if(t_id<m_length){
			return m_data[t_id];
		}
		return null;
	}
}
class c_TexData extends Object{
	public function m_TexData_new():c_TexData{
		return this;
	}
	internal var m_tex_count:int=0;
	internal var m_texture:Array=new_object_array(8);
	internal var m_tex_flags:Array=new_number_array(8);
	internal var m_tex_blend:Array=new_number_array(8);
	internal var m_tex_coords:Array=new_number_array(8);
	internal var m_tex_u_scale:Array=new_number_array(8);
	internal var m_tex_v_scale:Array=new_number_array(8);
	internal var m_tex_u_pos:Array=new_number_array(8);
	internal var m_tex_v_pos:Array=new_number_array(8);
	internal var m_tex_ang:Array=new_number_array(8);
	internal var m_tex_cube_mode:Array=new_number_array(8);
	internal var m_frame:Array=new_number_array(8);
	internal var m_tex_smooth:Array=new_number_array(8);
	internal var m_uv_clamp:int=0;
	internal static var m_null_tex:c_TTexture;
	public function p_UpdateTexture(t_surf:c_TSurface,t_ent:c_TEntity):int{
		m_tex_count=0;
		m_tex_count=t_ent.m_brush.m_no_texs;
		if(t_surf.m_brush.m_no_texs>m_tex_count){
			m_tex_count=t_surf.m_brush.m_no_texs;
		}
		for(var t_ix:int=0;t_ix<=m_tex_count-1;t_ix=t_ix+1){
			if(t_surf.m_brush.m_tex[t_ix]!=null || t_ent.m_brush.m_tex[t_ix]!=null){
				if(t_ent.m_brush.m_tex[t_ix]!=null){
					if(t_ent.m_brush.m_tex[t_ix].m_width==0){
						m_tex_count=0;
						break;
					}
					m_texture[t_ix]=t_ent.m_brush.m_tex[t_ix];
					m_tex_flags[t_ix]=t_ent.m_brush.m_tex[t_ix].m_flags;
					m_tex_blend[t_ix]=t_ent.m_brush.m_tex[t_ix].m_blend;
					m_tex_coords[t_ix]=t_ent.m_brush.m_tex[t_ix].m_coords;
					m_tex_u_scale[t_ix]=t_ent.m_brush.m_tex[t_ix].m_u_scale;
					m_tex_v_scale[t_ix]=t_ent.m_brush.m_tex[t_ix].m_v_scale;
					m_tex_u_pos[t_ix]=t_ent.m_brush.m_tex[t_ix].m_u_pos;
					m_tex_v_pos[t_ix]=t_ent.m_brush.m_tex[t_ix].m_v_pos;
					m_tex_ang[t_ix]=t_ent.m_brush.m_tex[t_ix].m_angle;
					m_tex_cube_mode[t_ix]=t_ent.m_brush.m_tex[t_ix].m_cube_mode;
					m_frame[t_ix]=t_ent.m_brush.m_tex[t_ix].m_tex_frame;
					m_tex_smooth[t_ix]=((t_ent.m_brush.m_tex[t_ix].m_tex_smooth)?1:0);
				}else{
					if(t_surf.m_brush.m_tex[t_ix].m_width==0){
						m_tex_count=t_ix-1;
						break;
					}
					m_texture[t_ix]=t_surf.m_brush.m_tex[t_ix];
					m_tex_flags[t_ix]=t_surf.m_brush.m_tex[t_ix].m_flags;
					m_tex_blend[t_ix]=t_surf.m_brush.m_tex[t_ix].m_blend;
					m_tex_coords[t_ix]=t_surf.m_brush.m_tex[t_ix].m_coords;
					m_tex_u_scale[t_ix]=t_surf.m_brush.m_tex[t_ix].m_u_scale;
					m_tex_v_scale[t_ix]=t_surf.m_brush.m_tex[t_ix].m_v_scale;
					m_tex_u_pos[t_ix]=t_surf.m_brush.m_tex[t_ix].m_u_pos;
					m_tex_v_pos[t_ix]=t_surf.m_brush.m_tex[t_ix].m_v_pos;
					m_tex_ang[t_ix]=t_surf.m_brush.m_tex[t_ix].m_angle;
					m_tex_cube_mode[t_ix]=t_surf.m_brush.m_tex[t_ix].m_cube_mode;
					m_frame[t_ix]=t_surf.m_brush.m_tex[t_ix].m_tex_frame;
					m_tex_smooth[t_ix]=((t_surf.m_brush.m_tex[t_ix].m_tex_smooth)?1:0);
				}
				if((m_tex_flags[t_ix]&16)!=0 || (m_tex_flags[t_ix]&32)!=0){
					m_uv_clamp=1;
				}else{
					m_uv_clamp=0;
				}
				if(m_texture[t_ix].m_width==0){
					m_texture[t_ix]=m_null_tex;
				}
			}
		}
		return 0;
	}
}
class c_ArrayIntMap3 extends Object{
	internal var m_data:Array=[];
	internal var m_length:int=0;
	public function m_ArrayIntMap_new():c_ArrayIntMap3{
		m_data=new_object_array(32);
		m_length=31;
		return this;
	}
	public function p_Get(t_id:int):Texture{
		if(t_id<m_length){
			return m_data[t_id];
		}
		return null;
	}
	public function p_Set5(t_id:int,t_obj:Texture):void{
		while(t_id>=m_length){
			m_length=m_length+32;
			m_data=resize_object_array(m_data,m_length+1);
		}
		m_data[t_id]=t_obj;
	}
}
internal function bb_flash11_AGALMatrix(t_m:c_Matrix):Array{
	return [t_m.m_grid[0][0],t_m.m_grid[1][0],t_m.m_grid[2][0],t_m.m_grid[3][0],t_m.m_grid[0][1],t_m.m_grid[1][1],t_m.m_grid[2][1],t_m.m_grid[3][1],t_m.m_grid[0][2],t_m.m_grid[1][2],t_m.m_grid[2][2],t_m.m_grid[3][2],t_m.m_grid[0][3],t_m.m_grid[1][3],t_m.m_grid[2][3],t_m.m_grid[3][3]];
}
class c_TPixmapFlash extends c_TPixmap implements c_IPixmapManager{
	public function m_TPixmapFlash_new():c_TPixmapFlash{
		super.m_TPixmap_new();
		return this;
	}
	public static function m_Init():int{
		if(!((c_TPixmap.m_manager)!=null)){
			c_TPixmap.m_manager=((new c_TPixmapFlash).m_TPixmapFlash_new());
		}
		if(!((c_TPixmap.m_preloader)!=null)){
			c_TPixmap.m_preloader=(new c_TPixmapPreloader).m_TPixmapPreloader_new((new c_PreloadFlash).m_PreloadFlash_new());
		}
		return 0;
	}
	internal var m_pixels:TPixmap=null;
	public override function p_ResizePixmap(t_neww:int,t_newh:int):c_TPixmap{
		var t_newpix:c_TPixmapFlash=(new c_TPixmapFlash).m_TPixmapFlash_new();
		if(t_neww<1 || t_newh<1){
			return (t_newpix);
		}
		t_newpix.m_pixels=TPixmap.ResizePixmap(m_pixels,t_neww,t_newh,true);
		t_newpix.m_width=t_neww;
		t_newpix.m_height=t_newh;
		return (t_newpix);
	}
	public override function p_ResizePixmapNoSmooth(t_neww:int,t_newh:int):c_TPixmap{
		var t_newpix:c_TPixmapFlash=(new c_TPixmapFlash).m_TPixmapFlash_new();
		if(t_neww<1 || t_newh<1){
			return (t_newpix);
		}
		t_newpix.m_pixels=TPixmap.ResizePixmap(m_pixels,t_neww,t_newh,false);
		t_newpix.m_width=t_neww;
		t_newpix.m_height=t_newh;
		return (t_newpix);
	}
	internal var m_format:int=0;
	internal var m_pitch:int=0;
	public function p_LoadPixmap(t_f:String):c_TPixmap{
		var t_p:c_TPixmapFlash=(new c_TPixmapFlash).m_TPixmapFlash_new();
		var t_info:Array=new_number_array(3);
		c_TPixmap.m_preloader.p_GetPixmapPreLoad((t_p),t_f);
		t_p.m_format=4;
		if((t_p.m_width)!=0){
			t_p.m_pitch=t_p.m_width;
		}
		if(t_p.m_width==0 || t_p.m_height==0 || !((t_p.m_pixels)!=null)){
			bb_tutility_Dprint("Image Not Preloaded: "+t_f,"","","","","");
		}
		return (t_p);
	}
	public function p_CreatePixmap(t_w:int,t_h:int,t_format:int):c_TPixmap{
		var t_p:c_TPixmapFlash=(new c_TPixmapFlash).m_TPixmapFlash_new();
		t_p.m_pixels=TPixmap.CreatePixmap(t_w,t_h);
		t_p.m_width=t_w;
		t_p.m_height=t_h;
		t_p.m_format=t_format;
		t_p.m_pitch=t_w;
		return (t_p);
	}
	public override function p_SetPixel(t_x:int,t_y:int,t_r:int,t_g:int,t_b:int,t_a:int):void{
		TPixmap.WritePixel(m_pixels,t_x,t_y,t_a<<24|t_r<<16|t_b<<8|t_g);
	}
	public override function p_MaskPixmap(t_r:int,t_g:int,t_b:int):void{
		m_pixels=TPixmap.MaskPixmap(m_pixels,0xff000000|t_r<<16|t_b<<8|t_g);
	}
	public override function p_FreePixmap():void{
		m_pixels=null;
	}
}
class c_PreloadFlash extends Object implements c_IPreloadManager{
	public function m_PreloadFlash_new():c_PreloadFlash{
		return this;
	}
	internal var m_p_map:c_ArrayIntMap4=(new c_ArrayIntMap4).m_ArrayIntMap_new();
	public function p_IsLoaded(t_file_id:int):Boolean{
		var t_f:c_PreloadData=m_p_map.p_Get(t_file_id);
		if((t_f)!=null){
			return TPixmap.CheckIsLoaded(t_f.m_data);
		}
		return false;
	}
	public function p_PreLoadData(t_f:String,t_id:int):void{
		if(t_id<1){
			return;
		}
		t_f=bb_data_FixDataPath(t_f);
		t_f=string_replace(t_f,"monkey://","");
		var t_d:c_PreloadData=(new c_PreloadData).m_PreloadData_new();
		t_d.m_id=t_id;
		t_d.m_data=TPixmap.LoadImageData(t_f);
		m_p_map.p_Set9(t_id,t_d);
	}
	public function p_SetPixmapFromID(t_pixmap:c_TPixmap,t_id:int,t_f:String):void{
		var t_p:c_TPixmapFlash=((t_pixmap) as c_TPixmapFlash);
		if(((t_p)!=null) && t_id>0){
			var t_d:c_PreloadData=m_p_map.p_Get(t_id);
			if((t_d)!=null){
				t_p.m_pixels=t_d.m_data;
				var t_info:Array=TPixmap.GetInfo(t_p.m_pixels);
				t_p.m_width=t_info[0];
				t_p.m_height=t_info[1];
			}
		}
	}
}
internal function bb_functions_CreateTexture(t_width:int,t_height:int,t_flags:int,t_frames:int):c_TTexture{
	return c_TTexture.m_CreateTexture(t_width,t_height,t_flags,t_frames,null);
}
internal function bb_functions_CreateSprite(t_parent:c_TEntity):c_TSprite{
	return c_TSprite.m_CreateSprite(t_parent);
}
internal function bb_mojographics_Transform2D(t_mat:c_Matrix,t_x:Number,t_y:Number,t_z:Number):Array{
	var t_t2d:Array=new_number_array(3);
	t_t2d[0]=t_mat.m_grid[0][0]*t_x+t_mat.m_grid[1][0]*t_y+t_mat.m_grid[3][0];
	t_t2d[1]=t_mat.m_grid[0][1]*t_x+t_mat.m_grid[1][1]*t_y+t_mat.m_grid[3][1];
	t_t2d[2]=t_z;
	return t_t2d;
}
class c_XMLError extends Object{
	public function m_XMLError_new():c_XMLError{
		return this;
	}
	internal var m_error:Boolean=false;
	internal var m_message:String="";
	internal var m_line:int=0;
	internal var m_column:int=0;
	internal var m_offset:int=0;
	public function p_Reset():void{
		m_error=false;
		m_message="";
		m_line=-1;
		m_column=-1;
		m_offset=-1;
	}
	public function p_Set6(t_message:String,t_line:int,t_column:int,t_offset:int):void{
		m_error=true;
		this.m_message=t_message;
		this.m_line=t_line;
		this.m_column=t_column;
		this.m_offset=t_offset;
	}
	public function p_ToString():String{
		if(m_error==false){
			return "";
		}
		var t_buffer:c_XMLStringBuffer=(new c_XMLStringBuffer).m_XMLStringBuffer_new(256);
		t_buffer.p_Add5("XMLError: ");
		if((m_message.length)!=0){
			t_buffer.p_Add5(m_message);
		}else{
			t_buffer.p_Add5("unknown error");
		}
		t_buffer.p_Add5(" [line:");
		if(m_line>-1){
			t_buffer.p_Add5(String(m_line));
		}else{
			t_buffer.p_Add5("??");
		}
		t_buffer.p_Add5("  column:");
		if(m_column>-1){
			t_buffer.p_Add5(String(m_column));
		}else{
			t_buffer.p_Add5("??");
		}
		t_buffer.p_Add5("  offset:");
		if(m_offset>-1){
			t_buffer.p_Add5(String(m_offset)+"]");
		}else{
			t_buffer.p_Add5("??]");
		}
		return t_buffer.p_value();
	}
}
class c_XMLNode extends Object{
	internal var m_value:String="";
	internal var m_valid:Boolean=false;
	internal var m_text:Boolean=false;
	internal var m_name:String="";
	public function m_XMLNode_new(t_name:String,t_valid:Boolean):c_XMLNode{
		if((t_name.length)!=0){
			this.m_name=t_name.toLowerCase();
		}
		this.m_valid=t_valid;
		return this;
	}
	public function m_XMLNode_new2():c_XMLNode{
		return this;
	}
	internal var m_doc:c_XMLDoc=null;
	internal var m_parent:c_XMLNode=null;
	internal var m_lastChild:c_XMLNode=null;
	internal var m_nextSibling:c_XMLNode=null;
	internal var m_previousSibling:c_XMLNode=null;
	internal var m_firstChild:c_XMLNode=null;
	internal var m_children:c_List13=(new c_List13).m_List_new();
	public function p_AddText(t_data:String):c_XMLNode{
		if(m_valid==false || m_text){
			return null;
		}
		m_value=m_value+t_data;
		var t_child:c_XMLNode=(new c_XMLNode).m_XMLNode_new(m_name,true);
		t_child.m_text=true;
		t_child.m_doc=m_doc;
		t_child.m_parent=this;
		t_child.m_value=t_data;
		if((m_lastChild)!=null){
			m_lastChild.m_nextSibling=t_child;
			t_child.m_previousSibling=m_lastChild;
			m_lastChild=t_child;
		}else{
			m_firstChild=t_child;
			m_lastChild=t_child;
		}
		m_children.p_AddLast13(t_child);
		return t_child;
	}
	internal var m_path:String="";
	internal var m_pathList:c_List13=null;
	internal var m_pathListNode:c_Node16=null;
	internal var m_line:int=0;
	internal var m_column:int=0;
	internal var m_offset:int=0;
	internal var m_attributes:c_StringMap3=(new c_StringMap3).m_StringMap_new();
	public function p_SetAttribute(t_id:String):void{
		if(m_valid==false){
			return;
		}
		t_id=t_id.toLowerCase();
		var t_attribute:c_XMLAttribute=m_attributes.p_Get2(t_id);
		if(t_attribute==null){
			m_attributes.p_Insert4(t_id,(new c_XMLAttribute).m_XMLAttribute_new(t_id,""));
		}else{
			t_attribute.m_value="";
		}
	}
	public function p_SetAttribute2(t_id:String,t_value:Boolean):void{
		if(m_valid==false){
			return;
		}
		t_id=t_id.toLowerCase();
		var t_attribute:c_XMLAttribute=m_attributes.p_Get2(t_id);
		if(t_attribute==null){
			m_attributes.p_Insert4(t_id,(new c_XMLAttribute).m_XMLAttribute_new(t_id,String((t_value)?1:0)));
		}else{
			t_attribute.m_value=String((t_value)?1:0);
		}
	}
	public function p_SetAttribute3(t_id:String,t_value:int):void{
		if(m_valid==false){
			return;
		}
		t_id=t_id.toLowerCase();
		var t_attribute:c_XMLAttribute=m_attributes.p_Get2(t_id);
		if(t_attribute==null){
			m_attributes.p_Insert4(t_id,(new c_XMLAttribute).m_XMLAttribute_new(t_id,String(t_value)));
		}else{
			t_attribute.m_value=String(t_value);
		}
	}
	public function p_SetAttribute4(t_id:String,t_value:Number):void{
		if(m_valid==false){
			return;
		}
		t_id=t_id.toLowerCase();
		var t_attribute:c_XMLAttribute=m_attributes.p_Get2(t_id);
		if(t_attribute==null){
			m_attributes.p_Insert4(t_id,(new c_XMLAttribute).m_XMLAttribute_new(t_id,String(t_value)));
		}else{
			t_attribute.m_value=String(t_value);
		}
	}
	public function p_SetAttribute5(t_id:String,t_value:String):void{
		if(m_valid==false){
			return;
		}
		t_id=t_id.toLowerCase();
		var t_attribute:c_XMLAttribute=m_attributes.p_Get2(t_id);
		if(t_attribute==null){
			m_attributes.p_Insert4(t_id,(new c_XMLAttribute).m_XMLAttribute_new(t_id,t_value));
		}else{
			t_attribute.m_value=t_value;
		}
	}
	public function p_AddChild(t_name:String,t_attributes:String,t_value:String):c_XMLNode{
		if(m_valid==false || m_text){
			return null;
		}
		var t_child:c_XMLNode=(new c_XMLNode).m_XMLNode_new(t_name,true);
		t_child.m_doc=m_doc;
		t_child.m_parent=this;
		t_child.m_value=t_value;
		t_child.m_path=m_path+"/"+t_child.m_name;
		t_child.m_pathList=m_doc.m_paths.p_Get2(t_child.m_path);
		if(t_child.m_pathList==null){
			t_child.m_pathList=(new c_List13).m_List_new();
			m_doc.m_paths.p_Set7(t_child.m_path,t_child.m_pathList);
		}
		t_child.m_pathListNode=t_child.m_pathList.p_AddLast13(t_child);
		if((t_attributes.length)!=0){
			var t_query:c_XMLAttributeQuery=(new c_XMLAttributeQuery).m_XMLAttributeQuery_new(t_attributes);
			if(t_query.p_Length2()>0){
				for(var t_index:int=0;t_index<t_query.p_Length2();t_index=t_index+1){
					t_child.p_SetAttribute5(t_query.m_items[t_index].m_id,t_query.m_items[t_index].m_value);
				}
			}
		}
		if((m_lastChild)!=null){
			m_lastChild.m_nextSibling=t_child;
			t_child.m_previousSibling=m_lastChild;
			m_lastChild=t_child;
		}else{
			m_firstChild=t_child;
			m_lastChild=t_child;
		}
		m_children.p_AddLast13(t_child);
		return t_child;
	}
	public function p_GetChild(t_text:Boolean):c_XMLNode{
		if(m_firstChild==null){
			return m_doc.m_nullNode;
		}
		if(t_text || m_firstChild.m_text==false){
			return m_firstChild;
		}
		var t_child:c_XMLNode=m_firstChild;
		while((t_child)!=null){
			if(t_child.m_text==false){
				return t_child;
			}
			t_child=t_child.m_nextSibling;
		}
		return m_doc.m_nullNode;
	}
	public function p_GetChild2(t_name:String,t_text:Boolean):c_XMLNode{
		if(m_firstChild==null){
			return m_doc.m_nullNode;
		}
		t_name=t_name.toLowerCase();
		var t_child:c_XMLNode=m_firstChild;
		while((t_child)!=null){
			if(t_child.m_name==t_name && (t_text || t_child.m_text==false)){
				return t_child;
			}
			t_child=t_child.m_nextSibling;
		}
		return m_doc.m_nullNode;
	}
	public function p_GetXMLAttribute(t_id:String):c_XMLAttribute{
		return m_attributes.p_Get2(t_id.toLowerCase());
	}
	public function p_GetChild3(t_name:String,t_attributes:String,t_text:Boolean):c_XMLNode{
		if(m_firstChild==null){
			return m_doc.m_nullNode;
		}
		t_name=t_name.toLowerCase();
		var t_query:c_XMLAttributeQuery=(new c_XMLAttributeQuery).m_XMLAttributeQuery_new(t_attributes);
		var t_child:c_XMLNode=m_firstChild;
		while((t_child)!=null){
			if(t_child.m_name==t_name && (t_text || t_child.m_text==false) && t_query.p_Test(t_child)){
				return t_child;
			}
			t_child=t_child.m_nextSibling;
		}
		return m_doc.m_nullNode;
	}
	public function p_GetChildren(t_result:c_List13,t_text:Boolean):c_List13{
		if(t_result==null){
			t_result=(new c_List13).m_List_new();
		}
		if(m_firstChild==null){
			return t_result;
		}
		if(m_firstChild!=null){
			var t_child:c_XMLNode=m_firstChild;
			while((t_child)!=null){
				if(t_text || t_child.m_text==false){
					t_result.p_AddLast13(t_child);
				}
				t_child=t_child.m_nextSibling;
			}
		}
		return t_result;
	}
	public function p_GetChildren2(t_name:String,t_result:c_List13,t_text:Boolean):c_List13{
		if(t_result==null){
			t_result=(new c_List13).m_List_new();
		}
		if(m_firstChild==null || t_name.length==0){
			return t_result;
		}
		t_name=t_name.toLowerCase();
		if(m_firstChild!=null){
			var t_child:c_XMLNode=m_firstChild;
			while((t_child)!=null){
				if(t_child.m_name==t_name && (t_text || t_child.m_text==false)){
					t_result.p_AddLast13(t_child);
				}
				t_child=t_child.m_nextSibling;
			}
		}
		return t_result;
	}
	public function p_GetChildren3(t_name:String,t_attributes:String,t_result:c_List13,t_text:Boolean):c_List13{
		if(t_result==null){
			t_result=(new c_List13).m_List_new();
		}
		if(m_firstChild==null || t_name.length==0 && t_attributes.length==0){
			return t_result;
		}
		t_name=t_name.toLowerCase();
		var t_query:c_XMLAttributeQuery=(new c_XMLAttributeQuery).m_XMLAttributeQuery_new(t_attributes);
		if(m_firstChild!=null){
			var t_child:c_XMLNode=m_firstChild;
			while((t_child)!=null){
				if((t_name.length==0 || t_child.m_name==t_name) && (t_text || t_child.m_text==false) && t_query.p_Test(t_child)){
					t_result.p_AddLast13(t_child);
				}
				t_child=t_child.m_nextSibling;
			}
		}
		return t_result;
	}
}
class c_XMLDoc extends c_XMLNode{
	internal var m_nullNode:c_XMLNode=null;
	internal var m_version:String="";
	internal var m_encoding:String="";
	internal var m_paths:c_StringMap2=(new c_StringMap2).m_StringMap_new();
	public function m_XMLDoc_new(t_name:String,t_version:String,t_encoding:String):c_XMLDoc{
		super.m_XMLNode_new2();
		m_valid=true;
		m_doc=this;
		m_nullNode=(new c_XMLNode).m_XMLNode_new("",false);
		m_nullNode.m_doc=this;
		this.m_name=t_name.toLowerCase();
		this.m_version=t_version;
		this.m_encoding=t_encoding;
		m_path=t_name;
		m_pathList=(new c_List13).m_List_new();
		m_pathListNode=m_pathList.p_AddLast13(this);
		m_paths.p_Insert3(m_path,m_pathList);
		return this;
	}
	public function m_XMLDoc_new2():c_XMLDoc{
		super.m_XMLNode_new2();
		return this;
	}
}
class c_XMLStringBuffer extends Object{
	internal var m_chunk:int=128;
	public function m_XMLStringBuffer_new(t_chunk:int):c_XMLStringBuffer{
		this.m_chunk=t_chunk;
		return this;
	}
	internal var m_count:int=0;
	public function p_Length2():int{
		return m_count;
	}
	internal var m_data:Array=[];
	public function p_Last(t_defaultValue:int):int{
		if(m_count==0){
			return t_defaultValue;
		}
		return m_data[m_count-1];
	}
	internal var m_dirty:int=0;
	public function p_Add4(t_asc:int):void{
		if(m_count==m_data.length){
			m_data=resize_number_array(m_data,m_data.length+m_chunk);
		}
		m_data[m_count]=t_asc;
		m_count+=1;
		m_dirty=1;
	}
	public function p_Add5(t_text:String):void{
		if(t_text.length==0){
			return;
		}
		if(m_count+t_text.length>=m_data.length){
			m_data=resize_number_array(m_data,(((m_data.length)+(m_chunk)*Math.ceil((t_text.length)/(m_chunk)))|0));
		}
		for(var t_textIndex:int=0;t_textIndex<t_text.length;t_textIndex=t_textIndex+1){
			m_data[m_count]=t_text.charCodeAt(t_textIndex);
			m_count+=1;
		}
		m_dirty=1;
	}
	public function p_Add6(t_text:String,t_offset:int,t_suggestedLength:int):void{
		var t_realLength:int=t_text.length-t_offset;
		if(t_suggestedLength>0 && t_suggestedLength<t_realLength){
			t_realLength=t_suggestedLength;
		}
		if(t_realLength==0){
			return;
		}
		if(m_count+t_realLength>=m_data.length){
			m_data=resize_number_array(m_data,(((m_data.length)+(m_chunk)*Math.ceil((t_realLength)/(m_chunk)))|0));
		}
		for(var t_textIndex:int=t_offset;t_textIndex<t_offset+t_realLength;t_textIndex=t_textIndex+1){
			m_data[m_count]=t_text.charCodeAt(t_textIndex);
			m_count+=1;
		}
		m_dirty=1;
	}
	internal var m_cache:String="";
	public function p_Clear():void{
		m_count=0;
		m_cache="";
		m_dirty=0;
	}
	public function p_Trim():Boolean{
		if(m_count==0){
			return false;
		}
		if(m_count==1 && (m_data[0]==32 || m_data[0]==9 || m_data[0]==10) || m_count==2 && (m_data[0]==32 || m_data[0]==9 || m_data[0]==10) && (m_data[1]==32 || m_data[1]==9 || m_data[1]==10)){
			this.p_Clear();
			return true;
		}
		var t_startIndex:int=0;
		for(t_startIndex=0;t_startIndex<m_count;t_startIndex=t_startIndex+1){
			if(m_data[t_startIndex]!=32 && m_data[t_startIndex]!=9 && m_data[t_startIndex]!=10){
				break;
			}
		}
		if(t_startIndex==m_count){
			this.p_Clear();
			return true;
		}
		var t_endIndex:int=0;
		for(t_endIndex=m_count-1;t_endIndex>=0;t_endIndex=t_endIndex+-1){
			if(m_data[t_endIndex]!=32 && m_data[t_endIndex]!=9 && m_data[t_endIndex]!=10){
				break;
			}
		}
		if(t_startIndex==0 && t_endIndex==m_count-1){
			return false;
		}
		m_count=t_endIndex-t_startIndex+1;
		if(t_startIndex>0){
			for(var t_trimIndex:int=0;t_trimIndex<m_count;t_trimIndex=t_trimIndex+1){
				m_data[t_trimIndex]=m_data[t_trimIndex+t_startIndex];
			}
		}
		return true;
	}
	public function p_value():String{
		if((m_dirty)!=0){
			m_dirty=0;
			if(m_count==0){
				m_cache="";
			}else{
				m_cache=string_fromchars(m_data.slice(0,m_count));
			}
		}
		return m_cache;
	}
}
class c_List13 extends Object{
	public function m_List_new():c_List13{
		return this;
	}
	internal var m__head:c_Node16=((new c_HeadNode13).m_HeadNode_new());
	public function p_AddLast13(t_data:c_XMLNode):c_Node16{
		return (new c_Node16).m_Node_new(m__head,m__head.m__pred,t_data);
	}
	public function m_List_new2(t_data:Array):c_List13{
		var t_:Array=t_data;
		var t_2:int=0;
		while(t_2<t_.length){
			var t_t:c_XMLNode=t_[t_2];
			t_2=t_2+1;
			this.p_AddLast13(t_t);
		}
		return this;
	}
	public function p_RemoveLast():c_XMLNode{
		var t_data:c_XMLNode=m__head.m__pred.m__data;
		m__head.m__pred.p_Remove();
		return t_data;
	}
	public function p_Equals4(t_lhs:c_XMLNode,t_rhs:c_XMLNode):Boolean{
		return t_lhs==t_rhs;
	}
	public function p_FindLast(t_value:c_XMLNode,t_start:c_Node16):c_Node16{
		while(t_start!=m__head){
			if(this.p_Equals4(t_value,t_start.m__data)){
				return t_start;
			}
			t_start=t_start.m__pred;
		}
		return null;
	}
	public function p_FindLast2(t_value:c_XMLNode):c_Node16{
		return this.p_FindLast(t_value,m__head.m__pred);
	}
	public function p_RemoveLast2(t_value:c_XMLNode):void{
		var t_node:c_Node16=this.p_FindLast2(t_value);
		if((t_node)!=null){
			t_node.p_Remove();
		}
	}
	public function p_IsEmpty():Boolean{
		return m__head.m__succ==m__head;
	}
	public function p_Last2():c_XMLNode{
		return m__head.m__pred.m__data;
	}
	public function p_ObjectEnumerator():c_Enumerator14{
		return (new c_Enumerator14).m_Enumerator_new(this);
	}
}
class c_Node16 extends Object{
	internal var m__succ:c_Node16=null;
	internal var m__pred:c_Node16=null;
	internal var m__data:c_XMLNode=null;
	public function m_Node_new(t_succ:c_Node16,t_pred:c_Node16,t_data:c_XMLNode):c_Node16{
		m__succ=t_succ;
		m__pred=t_pred;
		m__succ.m__pred=this;
		m__pred.m__succ=this;
		m__data=t_data;
		return this;
	}
	public function m_Node_new2():c_Node16{
		return this;
	}
	public function p_Remove():int{
		m__succ.m__pred=m__pred;
		m__pred.m__succ=m__succ;
		return 0;
	}
}
class c_HeadNode13 extends c_Node16{
	public function m_HeadNode_new():c_HeadNode13{
		super.m_Node_new2();
		m__succ=(this);
		m__pred=(this);
		return this;
	}
}
internal function bb_xml_XMLHasStringAtOffset(t_needle:String,t_haystack:String,t_offset:int):Boolean{
	if(t_offset+t_needle.length>t_haystack.length){
		return false;
	}
	for(var t_index:int=0;t_index<t_needle.length;t_index=t_index+1){
		if(t_needle.charCodeAt(t_index)!=t_haystack.charCodeAt(t_offset+t_index)){
			return false;
		}
	}
	return true;
}
internal function bb_xml_XMLFindNextAsc(t_data:String,t_asc:int,t_offset:int):int{
	var t_length:int=t_data.length;
	if(t_offset>=t_length){
		return -1;
	}
	if(t_offset<0){
		t_offset=0;
	}
	for(t_offset=t_offset;t_offset<t_length;t_offset=t_offset+1){
		if(t_data.charCodeAt(t_offset)==t_asc){
			return t_offset;
		}
	}
	return -1;
}
internal function bb_xml_XMLFindStringNotInQuotes(t_needle:String,t_haystack:String,t_offset:int):int{
	var t_needlePos:int=0;
	do{
		t_needlePos=t_haystack.indexOf(t_needle,t_offset);
		if(t_needlePos==-1){
			return -1;
		}
		t_offset=bb_xml_XMLFindNextAsc(t_haystack,34,t_offset);
		if(t_needlePos<t_offset || t_offset==-1){
			return t_needlePos;
		}
		t_offset=bb_xml_XMLFindNextAsc(t_haystack,34,t_offset+1);
		if(t_offset==-1){
			return -1;
		}
		t_offset+=1;
	}while(!(false));
	return 0;
}
class c_Map6 extends Object{
	public function m_Map_new():c_Map6{
		return this;
	}
	internal var m_root:c_Node17=null;
	public function p_Compare3(t_lhs:String,t_rhs:String):int{
		return 0;
	}
	public function p_RotateLeft4(t_node:c_Node17):int{
		var t_child:c_Node17=t_node.m_right;
		t_node.m_right=t_child.m_left;
		if((t_child.m_left)!=null){
			t_child.m_left.m_parent=t_node;
		}
		t_child.m_parent=t_node.m_parent;
		if((t_node.m_parent)!=null){
			if(t_node==t_node.m_parent.m_left){
				t_node.m_parent.m_left=t_child;
			}else{
				t_node.m_parent.m_right=t_child;
			}
		}else{
			m_root=t_child;
		}
		t_child.m_left=t_node;
		t_node.m_parent=t_child;
		return 0;
	}
	public function p_RotateRight4(t_node:c_Node17):int{
		var t_child:c_Node17=t_node.m_left;
		t_node.m_left=t_child.m_right;
		if((t_child.m_right)!=null){
			t_child.m_right.m_parent=t_node;
		}
		t_child.m_parent=t_node.m_parent;
		if((t_node.m_parent)!=null){
			if(t_node==t_node.m_parent.m_right){
				t_node.m_parent.m_right=t_child;
			}else{
				t_node.m_parent.m_left=t_child;
			}
		}else{
			m_root=t_child;
		}
		t_child.m_right=t_node;
		t_node.m_parent=t_child;
		return 0;
	}
	public function p_InsertFixup4(t_node:c_Node17):int{
		while(((t_node.m_parent)!=null) && t_node.m_parent.m_color==-1 && ((t_node.m_parent.m_parent)!=null)){
			if(t_node.m_parent==t_node.m_parent.m_parent.m_left){
				var t_uncle:c_Node17=t_node.m_parent.m_parent.m_right;
				if(((t_uncle)!=null) && t_uncle.m_color==-1){
					t_node.m_parent.m_color=1;
					t_uncle.m_color=1;
					t_uncle.m_parent.m_color=-1;
					t_node=t_uncle.m_parent;
				}else{
					if(t_node==t_node.m_parent.m_right){
						t_node=t_node.m_parent;
						this.p_RotateLeft4(t_node);
					}
					t_node.m_parent.m_color=1;
					t_node.m_parent.m_parent.m_color=-1;
					this.p_RotateRight4(t_node.m_parent.m_parent);
				}
			}else{
				var t_uncle2:c_Node17=t_node.m_parent.m_parent.m_left;
				if(((t_uncle2)!=null) && t_uncle2.m_color==-1){
					t_node.m_parent.m_color=1;
					t_uncle2.m_color=1;
					t_uncle2.m_parent.m_color=-1;
					t_node=t_uncle2.m_parent;
				}else{
					if(t_node==t_node.m_parent.m_left){
						t_node=t_node.m_parent;
						this.p_RotateRight4(t_node);
					}
					t_node.m_parent.m_color=1;
					t_node.m_parent.m_parent.m_color=-1;
					this.p_RotateLeft4(t_node.m_parent.m_parent);
				}
			}
		}
		m_root.m_color=1;
		return 0;
	}
	public function p_Set7(t_key:String,t_value:c_List13):Boolean{
		var t_node:c_Node17=m_root;
		var t_parent:c_Node17=null;
		var t_cmp:int=0;
		while((t_node)!=null){
			t_parent=t_node;
			t_cmp=this.p_Compare3(t_key,t_node.m_key);
			if(t_cmp>0){
				t_node=t_node.m_right;
			}else{
				if(t_cmp<0){
					t_node=t_node.m_left;
				}else{
					t_node.m_value=t_value;
					return false;
				}
			}
		}
		t_node=(new c_Node17).m_Node_new(t_key,t_value,-1,t_parent);
		if((t_parent)!=null){
			if(t_cmp>0){
				t_parent.m_right=t_node;
			}else{
				t_parent.m_left=t_node;
			}
			this.p_InsertFixup4(t_node);
		}else{
			m_root=t_node;
		}
		return true;
	}
	public function p_Insert3(t_key:String,t_value:c_List13):Boolean{
		return this.p_Set7(t_key,t_value);
	}
	public function p_FindNode2(t_key:String):c_Node17{
		var t_node:c_Node17=m_root;
		while((t_node)!=null){
			var t_cmp:int=this.p_Compare3(t_key,t_node.m_key);
			if(t_cmp>0){
				t_node=t_node.m_right;
			}else{
				if(t_cmp<0){
					t_node=t_node.m_left;
				}else{
					return t_node;
				}
			}
		}
		return t_node;
	}
	public function p_Get2(t_key:String):c_List13{
		var t_node:c_Node17=this.p_FindNode2(t_key);
		if((t_node)!=null){
			return t_node.m_value;
		}
		return null;
	}
}
class c_StringMap2 extends c_Map6{
	public function m_StringMap_new():c_StringMap2{
		super.m_Map_new();
		return this;
	}
	public override function p_Compare3(t_lhs:String,t_rhs:String):int{
		return string_compare(t_lhs,t_rhs);
	}
}
class c_Node17 extends Object{
	internal var m_key:String="";
	internal var m_right:c_Node17=null;
	internal var m_left:c_Node17=null;
	internal var m_value:c_List13=null;
	internal var m_color:int=0;
	internal var m_parent:c_Node17=null;
	public function m_Node_new(t_key:String,t_value:c_List13,t_color:int,t_parent:c_Node17):c_Node17{
		this.m_key=t_key;
		this.m_value=t_value;
		this.m_color=t_color;
		this.m_parent=t_parent;
		return this;
	}
	public function m_Node_new2():c_Node17{
		return this;
	}
}
class c_XMLAttributeQuery extends Object{
	internal var m_count:int=0;
	internal var m_items:Array=[];
	internal var m_chunk:int=32;
	public function m_XMLAttributeQuery_new(t_query:String):c_XMLAttributeQuery{
		var t_queryIndex:int=0;
		var t_queryAsc:int=0;
		var t_buffer:c_XMLStringBuffer=(new c_XMLStringBuffer).m_XMLStringBuffer_new(256);
		var t_isEscaped:Boolean=false;
		var t_processBuffer:Boolean=false;
		var t_processItem:Boolean=false;
		var t_hasId:Boolean=false;
		var t_hasValue:Boolean=false;
		var t_hasEquals:Boolean=false;
		var t_hasSepcial:Boolean=false;
		var t_itemId:String="";
		var t_itemValue:String="";
		for(t_queryIndex=0;t_queryIndex<t_query.length;t_queryIndex=t_queryIndex+1){
			t_queryAsc=t_query.charCodeAt(t_queryIndex);
			if(t_isEscaped){
				t_isEscaped=false;
				t_buffer.p_Add4(t_queryAsc);
			}else{
				var t_1:int=t_queryAsc;
				if(t_1==38){
					t_processBuffer=true;
					t_processItem=true;
				}else{
					if(t_1==61){
						t_processBuffer=true;
						t_hasEquals=true;
					}else{
						if(t_1==64){
							if(t_hasId==false){
								if(t_buffer.p_Length2()==0){
									t_hasSepcial=true;
								}
							}else{
								t_buffer.p_Add4(t_queryAsc);
							}
						}else{
							if(t_1==92){
								t_isEscaped=true;
							}else{
								if(t_hasId || (t_queryAsc==45 || t_queryAsc==95 || t_queryAsc>=48 && t_queryAsc<=57 || t_queryAsc>=65 && t_queryAsc<=90 || t_queryAsc>=97 && t_queryAsc<=122)){
									t_buffer.p_Add4(t_queryAsc);
								}
							}
						}
					}
				}
			}
			if(t_queryIndex==t_query.length-1){
				t_processBuffer=true;
				t_processItem=true;
				if(t_isEscaped && t_hasId){
					t_buffer.p_Add4(92);
				}
				if(t_hasEquals && t_buffer.p_Length2()==0){
					t_hasValue=true;
				}
			}
			if(t_processBuffer){
				t_processBuffer=false;
				if(t_hasId==false){
					t_itemId=t_buffer.p_value();
					t_buffer.p_Clear();
					t_hasId=t_itemId.length>0;
				}else{
					t_itemValue=t_buffer.p_value();
					t_buffer.p_Clear();
					t_hasValue=true;
				}
			}
			if(t_processItem){
				t_processItem=false;
				if(t_hasId){
					if(m_count==m_items.length){
						m_items=resize_object_array(m_items,m_items.length+m_chunk);
					}
					m_items[m_count]=(new c_XMLAttributeQueryItem).m_XMLAttributeQueryItem_new(t_itemId,t_itemValue,t_hasValue,t_hasSepcial);
					m_count+=1;
					t_itemId="";
					t_itemValue="";
					t_hasId=false;
					t_hasValue=false;
					t_hasSepcial=false;
				}
			}
		}
		return this;
	}
	public function m_XMLAttributeQuery_new2():c_XMLAttributeQuery{
		return this;
	}
	public function p_Length2():int{
		return m_count;
	}
	public function p_Test(t_node:c_XMLNode):Boolean{
		var t_attribute:c_XMLAttribute=null;
		for(var t_index:int=0;t_index<m_count;t_index=t_index+1){
			if(m_items[t_index].m_special==false){
				t_attribute=t_node.p_GetXMLAttribute(m_items[t_index].m_id);
				if(t_attribute==null || m_items[t_index].m_required && t_attribute.m_value!=m_items[t_index].m_value){
					return false;
				}
			}else{
				var t_2:String=m_items[t_index].m_id;
				if(t_2=="value"){
					if(m_items[t_index].m_required && t_node.m_value!=m_items[t_index].m_value){
						return false;
					}
				}
			}
		}
		return true;
	}
}
class c_XMLAttributeQueryItem extends Object{
	internal var m_id:String="";
	internal var m_value:String="";
	internal var m_required:Boolean=false;
	internal var m_special:Boolean=false;
	public function m_XMLAttributeQueryItem_new(t_id:String,t_value:String,t_required:Boolean,t_special:Boolean):c_XMLAttributeQueryItem{
		this.m_id=t_id;
		this.m_value=t_value;
		this.m_required=t_required;
		this.m_special=t_special;
		return this;
	}
	public function m_XMLAttributeQueryItem_new2():c_XMLAttributeQueryItem{
		return this;
	}
}
class c_XMLAttribute extends Object{
	internal var m_id:String="";
	internal var m_value:String="";
	public function m_XMLAttribute_new(t_id:String,t_value:String):c_XMLAttribute{
		this.m_id=t_id;
		this.m_value=t_value;
		return this;
	}
	public function m_XMLAttribute_new2():c_XMLAttribute{
		return this;
	}
}
class c_Map7 extends Object{
	public function m_Map_new():c_Map7{
		return this;
	}
	internal var m_root:c_Node18=null;
	public function p_Compare3(t_lhs:String,t_rhs:String):int{
		return 0;
	}
	public function p_FindNode2(t_key:String):c_Node18{
		var t_node:c_Node18=m_root;
		while((t_node)!=null){
			var t_cmp:int=this.p_Compare3(t_key,t_node.m_key);
			if(t_cmp>0){
				t_node=t_node.m_right;
			}else{
				if(t_cmp<0){
					t_node=t_node.m_left;
				}else{
					return t_node;
				}
			}
		}
		return t_node;
	}
	public function p_Get2(t_key:String):c_XMLAttribute{
		var t_node:c_Node18=this.p_FindNode2(t_key);
		if((t_node)!=null){
			return t_node.m_value;
		}
		return null;
	}
	public function p_RotateLeft5(t_node:c_Node18):int{
		var t_child:c_Node18=t_node.m_right;
		t_node.m_right=t_child.m_left;
		if((t_child.m_left)!=null){
			t_child.m_left.m_parent=t_node;
		}
		t_child.m_parent=t_node.m_parent;
		if((t_node.m_parent)!=null){
			if(t_node==t_node.m_parent.m_left){
				t_node.m_parent.m_left=t_child;
			}else{
				t_node.m_parent.m_right=t_child;
			}
		}else{
			m_root=t_child;
		}
		t_child.m_left=t_node;
		t_node.m_parent=t_child;
		return 0;
	}
	public function p_RotateRight5(t_node:c_Node18):int{
		var t_child:c_Node18=t_node.m_left;
		t_node.m_left=t_child.m_right;
		if((t_child.m_right)!=null){
			t_child.m_right.m_parent=t_node;
		}
		t_child.m_parent=t_node.m_parent;
		if((t_node.m_parent)!=null){
			if(t_node==t_node.m_parent.m_right){
				t_node.m_parent.m_right=t_child;
			}else{
				t_node.m_parent.m_left=t_child;
			}
		}else{
			m_root=t_child;
		}
		t_child.m_right=t_node;
		t_node.m_parent=t_child;
		return 0;
	}
	public function p_InsertFixup5(t_node:c_Node18):int{
		while(((t_node.m_parent)!=null) && t_node.m_parent.m_color==-1 && ((t_node.m_parent.m_parent)!=null)){
			if(t_node.m_parent==t_node.m_parent.m_parent.m_left){
				var t_uncle:c_Node18=t_node.m_parent.m_parent.m_right;
				if(((t_uncle)!=null) && t_uncle.m_color==-1){
					t_node.m_parent.m_color=1;
					t_uncle.m_color=1;
					t_uncle.m_parent.m_color=-1;
					t_node=t_uncle.m_parent;
				}else{
					if(t_node==t_node.m_parent.m_right){
						t_node=t_node.m_parent;
						this.p_RotateLeft5(t_node);
					}
					t_node.m_parent.m_color=1;
					t_node.m_parent.m_parent.m_color=-1;
					this.p_RotateRight5(t_node.m_parent.m_parent);
				}
			}else{
				var t_uncle2:c_Node18=t_node.m_parent.m_parent.m_left;
				if(((t_uncle2)!=null) && t_uncle2.m_color==-1){
					t_node.m_parent.m_color=1;
					t_uncle2.m_color=1;
					t_uncle2.m_parent.m_color=-1;
					t_node=t_uncle2.m_parent;
				}else{
					if(t_node==t_node.m_parent.m_left){
						t_node=t_node.m_parent;
						this.p_RotateRight5(t_node);
					}
					t_node.m_parent.m_color=1;
					t_node.m_parent.m_parent.m_color=-1;
					this.p_RotateLeft5(t_node.m_parent.m_parent);
				}
			}
		}
		m_root.m_color=1;
		return 0;
	}
	public function p_Set8(t_key:String,t_value:c_XMLAttribute):Boolean{
		var t_node:c_Node18=m_root;
		var t_parent:c_Node18=null;
		var t_cmp:int=0;
		while((t_node)!=null){
			t_parent=t_node;
			t_cmp=this.p_Compare3(t_key,t_node.m_key);
			if(t_cmp>0){
				t_node=t_node.m_right;
			}else{
				if(t_cmp<0){
					t_node=t_node.m_left;
				}else{
					t_node.m_value=t_value;
					return false;
				}
			}
		}
		t_node=(new c_Node18).m_Node_new(t_key,t_value,-1,t_parent);
		if((t_parent)!=null){
			if(t_cmp>0){
				t_parent.m_right=t_node;
			}else{
				t_parent.m_left=t_node;
			}
			this.p_InsertFixup5(t_node);
		}else{
			m_root=t_node;
		}
		return true;
	}
	public function p_Insert4(t_key:String,t_value:c_XMLAttribute):Boolean{
		return this.p_Set8(t_key,t_value);
	}
}
class c_StringMap3 extends c_Map7{
	public function m_StringMap_new():c_StringMap3{
		super.m_Map_new();
		return this;
	}
	public override function p_Compare3(t_lhs:String,t_rhs:String):int{
		return string_compare(t_lhs,t_rhs);
	}
}
class c_Node18 extends Object{
	internal var m_key:String="";
	internal var m_right:c_Node18=null;
	internal var m_left:c_Node18=null;
	internal var m_value:c_XMLAttribute=null;
	internal var m_color:int=0;
	internal var m_parent:c_Node18=null;
	public function m_Node_new(t_key:String,t_value:c_XMLAttribute,t_color:int,t_parent:c_Node18):c_Node18{
		this.m_key=t_key;
		this.m_value=t_value;
		this.m_color=t_color;
		this.m_parent=t_parent;
		return this;
	}
	public function m_Node_new2():c_Node18{
		return this;
	}
}
internal function bb_xml_ParseXML(t_raw:String,t_error:c_XMLError,t_options:int):c_XMLDoc{
	var t_rawLine:int=1;
	var t_rawColumn:int=1;
	var t_rawIndex:int=0;
	var t_rawAsc:int=0;
	var t_rawPos:int=0;
	var t_rawChunkStart:int=0;
	var t_rawChunkLength:int=0;
	var t_rawChunkEnd:int=0;
	var t_rawChunk:String="";
	var t_rawChunkIndex:int=0;
	var t_rawChunkAsc:int=0;
	var t_rawChunkExit:Boolean=false;
	var t_doc:c_XMLDoc=null;
	var t_parent:c_XMLNode=null;
	var t_current:c_XMLNode=null;
	var t_textNode:c_XMLNode=null;
	var t_whitespaceBuffer:c_XMLStringBuffer=(new c_XMLStringBuffer).m_XMLStringBuffer_new(1024);
	var t_attributeBuffer:c_XMLStringBuffer=(new c_XMLStringBuffer).m_XMLStringBuffer_new(1024);
	var t_processAttributeBuffer:Boolean=false;
	var t_processTag:Boolean=false;
	var t_tagName:String="";
	var t_formatVersion:String="";
	var t_formatEncoding:String="";
	var t_attributeId:String="";
	var t_attributeValue:String="";
	var t_inTag:Boolean=false;
	var t_inQuote:Boolean=false;
	var t_inFormat:Boolean=false;
	var t_isCloseSelf:Boolean=false;
	var t_isSingleAttribute:Boolean=false;
	var t_hasFormat:Boolean=false;
	var t_hasTagName:Boolean=false;
	var t_hasTagClose:Boolean=false;
	var t_hasAttributeId:Boolean=false;
	var t_hasAttributeValue:Boolean=false;
	var t_hasEquals:Boolean=false;
	var t_waitTagClose:Boolean=false;
	var t_stack:c_List13=(new c_List13).m_List_new();
	var t_quoteAsc:int=0;
	if((t_error)!=null){
		t_error.p_Reset();
	}
	if(t_raw.length==0){
		if((t_error)!=null){
			t_error.p_Set6("no xml data",-1,-1,-1);
		}
		return null;
	}
	for(t_rawIndex=0;t_rawIndex<t_raw.length;t_rawIndex=t_rawIndex+1){
		t_rawAsc=t_raw.charCodeAt(t_rawIndex);
		if(t_inTag==false){
			var t_3:int=t_rawAsc;
			if(t_3==9 || t_3==32){
				if(((t_whitespaceBuffer.p_Length2())!=0) || ((t_parent)!=null) && ((t_parent.m_value.length)!=0)){
					var t_lastAsc:int=t_whitespaceBuffer.p_Last(-1);
					if((t_options&1)==0 || ((t_whitespaceBuffer.p_Length2())!=0) && t_lastAsc!=9 && t_lastAsc!=32){
						if(t_parent==null){
							if((t_error)!=null){
								t_error.p_Set6("illegal character",t_rawLine,t_rawColumn,t_rawIndex);
							}
							return null;
						}
						t_whitespaceBuffer.p_Add4(t_rawAsc);
					}
				}
				t_rawColumn+=1;
			}else{
				if(t_3==10){
					t_rawLine+=1;
					t_rawColumn=1;
					if((t_options&2)==0){
						t_whitespaceBuffer.p_Add4(t_rawAsc);
					}
				}else{
					if(t_3==13){
					}else{
						if(t_3==60){
							if(((t_parent)!=null) && ((t_whitespaceBuffer.p_Length2())!=0)){
								if((t_options&1)==1){
									t_whitespaceBuffer.p_Trim();
								}
								if((t_whitespaceBuffer.p_Length2())!=0){
									t_textNode=t_parent.p_AddText(t_whitespaceBuffer.p_value());
									t_whitespaceBuffer.p_Clear();
								}
							}
							if(bb_xml_XMLHasStringAtOffset("<?xml",t_raw,t_rawIndex)){
								if(t_hasFormat){
									if((t_error)!=null){
										t_error.p_Set6("duplicate xml format",t_rawLine,t_rawColumn,t_rawIndex);
									}
									return null;
								}
								if(t_doc!=null){
									if((t_error)!=null){
										t_error.p_Set6("doc format should be defined before root node",t_rawLine,t_rawColumn,t_rawIndex);
									}
									return null;
								}
								t_inTag=true;
								t_inFormat=true;
								t_rawColumn+="<?xml".length;
								t_rawIndex=t_rawPos+"<?xml".length-1;
							}else{
								if(bb_xml_XMLHasStringAtOffset("<!DOCTYPE",t_raw,t_rawIndex)){
									t_rawPos=bb_xml_XMLFindStringNotInQuotes(">",t_raw,t_rawIndex+"<!DOCTYPE".length);
									if(t_rawPos==-1){
										if((t_error)!=null){
											t_error.p_Set6("doctype not closed",t_rawLine,t_rawColumn,t_rawIndex);
										}
										return null;
									}
									t_rawChunkStart=t_rawIndex+"<!DOCTYPE".length;
									t_rawChunkLength=t_rawPos-(t_rawIndex+"<!DOCTYPE".length);
									t_rawChunkEnd=t_rawChunkStart+t_rawChunkLength;
									for(t_rawChunkIndex=t_rawChunkStart;t_rawChunkIndex<t_rawChunkEnd;t_rawChunkIndex=t_rawChunkIndex+1){
										t_rawChunkAsc=t_raw.charCodeAt(t_rawChunkIndex);
										if(t_rawChunkAsc==10){
											t_rawLine+=1;
											t_rawColumn=1;
										}else{
											t_rawColumn+=1;
										}
									}
									t_rawIndex=t_rawPos+">".length-1;
								}else{
									if(bb_xml_XMLHasStringAtOffset("<!--",t_raw,t_rawIndex)){
										t_rawPos=t_raw.indexOf("-->",t_rawIndex+"<!--".length);
										if(t_rawPos==-1){
											if((t_error)!=null){
												t_error.p_Set6("comment not closed",t_rawLine,t_rawColumn,t_rawIndex);
											}
											return null;
										}
										t_rawChunkStart=t_rawIndex+"<!--".length;
										t_rawChunkLength=t_rawPos-(t_rawIndex+"<!--".length);
										t_rawChunkEnd=t_rawChunkStart+t_rawChunkLength;
										for(t_rawChunkIndex=t_rawChunkStart;t_rawChunkIndex<t_rawChunkEnd;t_rawChunkIndex=t_rawChunkIndex+1){
											t_rawChunkAsc=t_raw.charCodeAt(t_rawChunkIndex);
											if(t_rawChunkAsc==10){
												t_rawLine+=1;
												t_rawColumn=1;
											}else{
												t_rawColumn+=1;
											}
										}
										t_rawIndex=t_rawPos+"-->".length-1;
									}else{
										if(bb_xml_XMLHasStringAtOffset("<![CDATA[",t_raw,t_rawIndex)){
											t_rawPos=t_raw.indexOf("]]>",t_rawIndex+"<![CDATA[".length);
											if(t_rawPos==-1){
												if((t_error)!=null){
													t_error.p_Set6("cdata not closed",t_rawLine,t_rawColumn,t_rawIndex);
												}
												return null;
											}
											if(t_parent==null){
												if((t_error)!=null){
													t_error.p_Set6("unexepcted cdata",t_rawLine,t_rawColumn,t_rawIndex);
												}
												return null;
											}
											t_rawChunkStart=t_rawIndex+"<![CDATA[".length;
											t_rawChunkLength=t_rawPos-(t_rawIndex+"<![CDATA[".length);
											t_rawChunkEnd=t_rawChunkStart+t_rawChunkLength;
											for(t_rawChunkIndex=t_rawChunkStart;t_rawChunkIndex<t_rawChunkEnd;t_rawChunkIndex=t_rawChunkIndex+1){
												t_rawChunkAsc=t_raw.charCodeAt(t_rawChunkIndex);
												if(t_rawChunkAsc==10){
													t_rawLine+=1;
													t_rawColumn=1;
												}else{
													t_rawColumn+=1;
												}
											}
											t_whitespaceBuffer.p_Add6(t_raw,t_rawChunkStart,t_rawChunkLength);
											if(((t_parent)!=null) && ((t_whitespaceBuffer.p_Length2())!=0)){
												t_textNode=t_parent.p_AddText(t_whitespaceBuffer.p_value());
												t_whitespaceBuffer.p_Clear();
											}
											t_rawIndex=t_rawPos+"]]>".length-1;
										}else{
											t_inTag=true;
											if((t_whitespaceBuffer.p_Length2())!=0){
												if((t_options&1)==1){
													t_whitespaceBuffer.p_Trim();
												}
												if((t_whitespaceBuffer.p_Length2())!=0){
													if((t_options&1)==1){
														t_whitespaceBuffer.p_Trim();
													}
													if((t_whitespaceBuffer.p_Length2())!=0){
														t_textNode=t_parent.p_AddText(t_whitespaceBuffer.p_value());
														t_whitespaceBuffer.p_Clear();
													}
												}
											}
											t_rawColumn+=1;
										}
									}
								}
							}
						}else{
							if(t_3==62){
								if((t_error)!=null){
									t_error.p_Set6("unexpected close bracket",t_rawLine,t_rawColumn,t_rawIndex);
								}
								return null;
							}else{
								if(t_parent==null){
									if((t_error)!=null){
										t_error.p_Set6("illegal character",t_rawLine,t_rawColumn,t_rawIndex);
									}
									return null;
								}
								t_whitespaceBuffer.p_Add4(t_rawAsc);
								t_rawColumn+=1;
							}
						}
					}
				}
			}
		}else{
			if(t_waitTagClose){
				var t_4:int=t_rawAsc;
				if(t_4==9){
					t_rawColumn+=1;
				}else{
					if(t_4==10){
						t_rawLine+=1;
						t_rawColumn=1;
					}else{
						if(t_4==13){
						}else{
							if(t_4==32){
								t_rawColumn+=1;
							}else{
								if(t_4==62){
									t_waitTagClose=false;
									t_processTag=true;
								}else{
									if((t_error)!=null){
										t_error.p_Set6("unexpected character",t_rawLine,t_rawColumn,t_rawIndex);
									}
									return null;
								}
							}
						}
					}
				}
			}else{
				if(t_inQuote==false){
					var t_5:int=t_rawAsc;
					if(t_5==9){
						t_rawColumn+=1;
						if((t_attributeBuffer.p_Length2())!=0){
							t_processAttributeBuffer=true;
						}
					}else{
						if(t_5==10){
							t_rawLine+=1;
							t_rawColumn=1;
							if((t_attributeBuffer.p_Length2())!=0){
								t_processAttributeBuffer=true;
							}
						}else{
							if(t_5==13){
							}else{
								if(t_5==32){
									t_rawColumn+=1;
									if((t_attributeBuffer.p_Length2())!=0){
										t_processAttributeBuffer=true;
									}
								}else{
									if(t_5==34 || t_5==39){
										t_quoteAsc=t_rawAsc;
										t_inQuote=true;
										if(t_hasTagClose || t_hasTagName==false && t_inFormat==false || t_hasEquals==false || ((t_attributeBuffer.p_Length2())!=0)){
											if((t_error)!=null){
												t_error.p_Set6("unexpected quote",t_rawLine,t_rawColumn,t_rawIndex);
											}
											return null;
										}
										t_rawColumn+=1;
										if((t_attributeBuffer.p_Length2())!=0){
											t_processAttributeBuffer=true;
										}
									}else{
										if(t_5==47){
											if(t_hasTagClose || t_hasEquals){
												if((t_error)!=null){
													t_error.p_Set6("unexpected slash",t_rawLine,t_rawColumn,t_rawIndex);
												}
												return null;
											}
											if((t_attributeBuffer.p_Length2())!=0){
												t_processAttributeBuffer=true;
											}
											if(t_hasTagName==false){
												if(t_processAttributeBuffer){
													t_isCloseSelf=true;
													t_waitTagClose=true;
												}else{
													t_hasTagClose=true;
												}
											}else{
												t_hasTagClose=true;
												t_isCloseSelf=true;
												t_waitTagClose=true;
											}
											t_rawColumn+=1;
										}else{
											if(t_5==61){
												t_rawColumn+=1;
												if(t_hasTagClose || t_hasTagName==false && t_inFormat==false || t_hasEquals || t_hasAttributeId || t_attributeBuffer.p_Length2()==0){
													if((t_error)!=null){
														t_error.p_Set6("unexpected equals",t_rawLine,t_rawColumn,t_rawIndex);
													}
													return null;
												}
												t_processAttributeBuffer=true;
												t_hasEquals=true;
											}else{
												if(t_5==62){
													if(t_hasEquals || t_hasTagName==false && t_attributeBuffer.p_Length2()==0){
														if((t_error)!=null){
															t_error.p_Set6("unexpected close bracket",t_rawLine,t_rawColumn,t_rawIndex);
														}
														return null;
													}
													if((t_attributeBuffer.p_Length2())!=0){
														t_processAttributeBuffer=true;
													}
													t_processTag=true;
													t_rawColumn+=1;
												}else{
													if(t_5==63){
														if(t_inFormat==false || t_rawIndex==t_raw.length-1 || t_raw.charCodeAt(t_rawIndex+1)!=62){
															if((t_error)!=null){
																t_error.p_Set6("unexpected questionmark",t_rawLine,t_rawColumn,t_rawIndex);
															}
															return null;
														}
														t_processTag=true;
														t_rawIndex+=1;
														t_rawColumn+=1;
													}else{
														if(t_rawAsc==45 || t_rawAsc==58 || t_rawAsc==95 || t_rawAsc>=48 && t_rawAsc<=57 || t_rawAsc>=65 && t_rawAsc<=90 || t_rawAsc>=97 && t_rawAsc<=122){
															if(t_hasTagClose==true && t_hasTagName==true){
																if((t_error)!=null){
																	t_error.p_Set6("unexpected character",t_rawLine,t_rawColumn,t_rawIndex);
																}
																return null;
															}
															if(t_hasAttributeId && t_hasEquals==false){
																t_isSingleAttribute=true;
																t_processAttributeBuffer=true;
															}else{
																t_attributeBuffer.p_Add4(t_rawAsc);
															}
															t_rawColumn+=1;
														}else{
															if((t_error)!=null){
																t_error.p_Set6("illegal character",t_rawLine,t_rawColumn,t_rawIndex);
															}
															return null;
														}
													}
												}
											}
										}
									}
								}
							}
						}
					}
				}else{
					if(t_rawAsc==t_quoteAsc){
						t_inQuote=false;
						t_processAttributeBuffer=true;
					}else{
						t_attributeBuffer.p_Add4(t_rawAsc);
					}
				}
				if(t_processAttributeBuffer){
					t_processAttributeBuffer=false;
					if(t_hasTagName==false && t_inFormat==false){
						if(t_hasTagClose==false){
							t_tagName=t_attributeBuffer.p_value();
							if(t_parent==null){
								if(t_doc==null){
									t_doc=(new c_XMLDoc).m_XMLDoc_new(t_tagName,t_formatVersion,t_formatEncoding);
									t_doc.m_doc=t_doc;
									t_doc.m_parent=null;
									t_doc.m_line=t_rawLine;
									t_doc.m_column=t_rawColumn;
									t_doc.m_offset=t_rawIndex;
									t_current=(t_doc);
								}else{
									if((t_error)!=null){
										t_error.p_Set6("duplicate root",t_rawLine,t_rawColumn,t_rawIndex);
									}
									return null;
								}
							}else{
								t_current=t_parent.p_AddChild(t_tagName,"","");
								t_current.m_line=t_rawLine;
								t_current.m_column=t_rawColumn;
								t_current.m_offset=t_rawIndex;
							}
							t_hasTagName=true;
						}else{
							t_tagName=t_attributeBuffer.p_value().toLowerCase();
							if(t_parent==null || t_tagName!=t_parent.m_name){
								if((t_error)!=null){
									t_error.p_Set6("mismatched end tag",t_rawLine,t_rawColumn,t_rawIndex);
								}
								return null;
							}
							t_waitTagClose=true;
							t_hasTagName=true;
						}
					}else{
						if(t_hasAttributeId==false){
							t_attributeId=t_attributeBuffer.p_value().toLowerCase();
							t_hasAttributeId=true;
						}else{
							t_attributeValue=t_attributeBuffer.p_value();
							t_hasAttributeValue=true;
						}
						if(t_processTag && t_hasAttributeId || t_hasAttributeId && t_hasAttributeValue || t_isSingleAttribute || t_hasTagClose){
							if(t_inFormat==false){
								t_current.p_SetAttribute5(t_attributeId,t_attributeValue);
							}else{
								var t_6:String=t_attributeId;
								if(t_6=="version"){
									t_formatVersion=t_attributeValue;
								}else{
									if(t_6=="encoding"){
										t_formatEncoding=t_attributeValue;
									}
								}
							}
							t_attributeId="";
							t_attributeValue="";
							t_hasAttributeId=false;
							t_hasAttributeValue=false;
							t_hasEquals=false;
						}
					}
					t_attributeBuffer.p_Clear();
				}
				if(t_isSingleAttribute){
					t_isSingleAttribute=false;
					t_attributeBuffer.p_Add4(t_rawAsc);
				}
			}
			if(t_processTag){
				t_processTag=false;
				if(t_inFormat==false){
					if(t_hasTagClose==false && t_isCloseSelf==false){
						t_parent=t_current;
						t_current=null;
						t_stack.p_AddLast13(t_parent);
					}
					if(t_isCloseSelf){
						t_hasTagClose=true;
					}
					if(t_hasTagClose==true){
						if(t_isCloseSelf==false){
							if((t_whitespaceBuffer.p_Length2())!=0){
								if((t_options&1)==1){
									t_whitespaceBuffer.p_Trim();
								}
								if((t_whitespaceBuffer.p_Length2())!=0){
									t_parent.p_AddText(t_whitespaceBuffer.p_value());
									t_whitespaceBuffer.p_Clear();
								}
							}
							t_stack.p_RemoveLast();
							if(t_stack.p_IsEmpty()){
								t_parent=null;
							}else{
								t_parent=t_stack.p_Last2();
							}
						}else{
							t_isCloseSelf=false;
						}
					}
				}else{
					t_hasFormat=true;
					t_inFormat=false;
				}
				t_inTag=false;
				t_hasTagClose=false;
				t_hasTagName=false;
				t_waitTagClose=false;
				t_tagName="";
			}
		}
	}
	if(t_inTag || ((t_parent)!=null) || t_doc==null){
		if((t_error)!=null){
			t_error.p_Set6("unexpected end of xml",t_rawLine,t_rawColumn,t_rawIndex);
		}
		return null;
	}
	return t_doc;
}
class c_Enumerator14 extends Object{
	internal var m__list:c_List13=null;
	internal var m__curr:c_Node16=null;
	public function m_Enumerator_new(t_list:c_List13):c_Enumerator14{
		m__list=t_list;
		m__curr=t_list.m__head.m__succ;
		return this;
	}
	public function m_Enumerator_new2():c_Enumerator14{
		return this;
	}
	public function p_HasNext():Boolean{
		while(m__curr.m__succ.m__pred!=m__curr){
			m__curr=m__curr.m__succ;
		}
		return m__curr!=m__list.m__head;
	}
	public function p_NextObject():c_XMLNode{
		var t_data:c_XMLNode=m__curr.m__data;
		m__curr=m__curr.m__succ;
		return t_data;
	}
}
internal function bb_asyncevent_RemoveAsyncEventSource(t_source:c_IAsyncEventSource):void{
	if(t_source==bb_asyncevent__current){
		bb_asyncevent__current=null;
	}
	bb_asyncevent__sources.p_RemoveEach3(t_source);
}
internal function bb_sknxmlloader_mysplit(t_mystring:String,t_ch:String):Array{
	var t_k:int=0;
	var t_s:int=0;
	var t_l:int=t_mystring.length;
	var t_part:String="";
	var t_krs:Array=string_tochars(t_mystring);
	var t_res:c_StringList=(new c_StringList).m_StringList_new2();
	t_s=1;
	for(t_k=1;t_k<=t_l;t_k=t_k+1){
		if(String.fromCharCode(t_krs[t_k])==t_ch){
			t_res.p_AddLast4(t_part);
			t_part="";
		}else{
			t_part=t_part+String.fromCharCode(t_krs[t_k]);
		}
	}
	return t_res.p_ToArray();
}
internal function bb_tutility_Dprint(t_x:String,t_y:String,t_z:String,t_a:String,t_b:String,t_c:String):int{
	var t_st:String=t_x+" "+t_y+" "+t_z+" "+t_a+" "+t_b+" "+t_c;
	print(t_st);
	return 0;
}
class c_PreloadData extends Object{
	internal var m_data:TPixmap=null;
	public function m_PreloadData_new():c_PreloadData{
		return this;
	}
	internal var m_id:int=0;
}
class c_ArrayIntMap4 extends Object{
	internal var m_data:Array=[];
	internal var m_length:int=0;
	public function m_ArrayIntMap_new():c_ArrayIntMap4{
		m_data=new_object_array(32);
		m_length=31;
		return this;
	}
	public function p_Get(t_id:int):c_PreloadData{
		if(t_id<m_length){
			return m_data[t_id];
		}
		return null;
	}
	public function p_Set9(t_id:int,t_obj:c_PreloadData):void{
		while(t_id>=m_length){
			m_length=m_length+32;
			m_data=resize_object_array(m_data,m_length+1);
		}
		m_data[t_id]=t_obj;
	}
}
function bbInit():void{
	bb_app2__app=null;
	bb_app2__delegate=null;
	bb_app2__game=BBGame.Game();
	bb_graphics_device=null;
	bb_graphics_context=(new c_GraphicsContext).m_GraphicsContext_new();
	c_Image.m_DefaultFlags=0;
	bb_audio_device=null;
	bb_input_device=null;
	bb_app2__devWidth=0;
	bb_app2__devHeight=0;
	bb_app2__displayModes=[];
	bb_app2__desktopMode=null;
	bb_graphics_renderDevice=null;
	bb_app2__updateRate=0;
	c_TRender.m_shader2D=((new c_BlankShader).m_BlankShader_new());
	c_TRender.m_render=null;
	c_MojoEmulationDevice.m__device=null;
	c_MojoEmulationDevice.m__olddevice=null;
	c_MojoEmulationDevice.m__quadCache=null;
	c_FlashMiniB3D.m_driver=(new Driver3D);
	c_TEntity.m_entity_list=(new c_EntityList).m_EntityList_new();
	c_TTexture.m_useGlobalResizeSmooth=true;
	c_TRender.m_draw_list=(new c_List3).m_List_new();
	c_MojoEmulationDevice.m_firstTimeRun=false;
	c_TPixmap.m_preloader=null;
	c_Stack2.m_NIL=null;
	c_MiniB3DApp.m__resumed=false;
	c_TRender.m_tris_rendered=0;
	c_TTexture.m_tex_bind_stack=(new c_TextureStack).m_TextureStack_new();
	c_Stack3.m_NIL=null;
	c_TCamera.m_cam_list=(new c_EntityList2).m_EntityList_new();
	c_TShader.m_process_list=(new c_List6).m_List_new();
	c_TShader.m_g_shader=null;
	c_TLight.m_light_list=(new c_List7).m_List_new();
	c_TRender.m_render_list=(new c_RenderAlphaList).m_RenderAlphaList_new();
	c_TRender.m_render_alpha_list=(new c_RenderAlphaList).m_RenderAlphaList_new();
	c_TRender.m_wireframe=0;
	c_TRender.m_temp_shader=null;
	c_ShortBuffer.m_i2f=null;
	c_TRender.m_alpha_pass=0;
	c_TRender.m_camera2D=(new c_TCamera).m_TCamera_new();
	c_TRender.m_width=0;
	c_TRender.m_height=0;
	c_MiniB3DApp.m__suspend=false;
	bb_asyncevent__sources=(new c_Stack4).m_Stack_new();
	c_TEntity.m_temp_mat=(new c_Matrix).m_Matrix_new();
	c_TBone.m_t_mat=(new c_Matrix).m_Matrix_new();
	c_TBone.m_new_mat=(new c_Matrix).m_Matrix_new();
	c_TLight.m_no_lights=0;
	c_TLight.m_max_lights=8;
	c_TPixmap.m_manager=null;
	c_TText.m_mask_color=0;
	c_TTextureFilter.m_filter_list=(new c_List11).m_List_new();
	c_TTexture.m_tex_list=(new c_List12).m_List_new();
	bb_asyncevent__current=null;
	c_Stack4.m_NIL=null;
	c_TShaderFlash.m_driver=null;
	c_TShaderFlash.m_g_id=0;
	c_MultiShader.m_init=false;
	c_FullBrightOneTexShader.m_VP="m44 vt1, va0, vc0\nmov v0, va1\nmov v1, va2\nmov vt0, va3\nmov vt0, vc4\nmov vt0, vc8\nmax vt3, vc18.xxxx, va1.xyzw\nmul v0, vc16, vt3\nmov v0.w, vt3.w\nadd vt0.x, vc23.x, va2.x\nmul vt0.x, vc23.z, vt0.x\nadd vt0.y, va2.y, vc23.y\nmul vt0.y, vc23.w, vt0.y\nsub vt0.x, vt0.x, vt0.y\nmul v1.x, vc24.x, vt0.x\nadd vt0.x, vc23.x, va2.x\nmul vt0.x, vc23.w, vt0.x\nadd vt0.y, va2.y, vc23.y\nmul vt0.y, vc23.z, vt0.y\nadd vt0.x, vt0.x, vt0.y\nmul v1.y, vc24.y, vt0.x\nmov op, vt1\n\n";
	c_FullBrightOneTexShader.m_FP="tex ft1, v1, fs0 <2d,TEXTURE_WRAP,linear>\nmov ft2, v0\nmul ft2, ft1, ft2\nALPHATESTmov oc, ft2\n";
	c_OneLightOneTexShader.m_VP="m44 vt1, va0, vc0\nmov v0, va1\nmov v1, va2\nm44 vt3, va3.xyz, vc8\nnrm vt3.xyz, vt3.xyz\nmov vt4.x, vc12.w\nmov vt4.y, vc13.w\nmov vt4.z, vc14.w\nm44 vt0, va0, vc4\nsub vt0, vt4.xyz, vt0.xyz\nm44 vt7, vt4.xyz, vc12\ndp3 vt5, vt0.xyz, vt0.xyz\nsqt vt5,vt5\nmul vt6.x, vc27.y, vt5\nadd vt6.x, vc27.x, vt6.x\nrcp vt6.x,vt6.x\nmov vt5.x, vc26.y\nadd vt5.x, vt5.x, vc26.z\nmul vt6.x, vt6.x, vt5.x\nmov vt5.x, vc26.x\nsge vt5.x, vt5.x, vc26.y\nadd vt6.x, vt6.x, vt5.x\nmul vt7, vt7, vc26.xxxx\nmul vt0, vt0, vc26.yyyy\nadd vt0, vt7, vt0\ndp3 vt0.xyz, vt0.xyz, vt3.xyz\nmul vt0.xyz, vt0.xyz, vt6.xxx\nsat vt0.xyz, vt0.xyz\nmax vt0.xyz, vt0.xyz, vc17.xyz\nmax vt3, vc18.xxxx, va1.xyzw\nmul vt3, vc16.xyzw, vt3.xyzw\nmul vt3.xyz, vt3.xyz, vc22.xyz\nmul v0, vt3.xyz, vt0.xyz\nmov v0.w, vt3.w\nmov op, vt1\n\n";
	c_OneLightOneTexShader.m_FP="tex ft1, v1, fs0 <2d,TEXTURE_WRAP,linear>\nALPHATESTmul ft2, ft1, v0\nmov oc, ft2\n";
	c_OneLightOneTexShader.m_alphaTest="sub ft3.x ft1.w fc25.x\nkil ft3.x\n";
	c_FullBrightOneTexShader.m_alphaTest="sub ft3.x ft1.w fc25.x\nkil ft3.x\n";
	c_TShader.m_default_shader=null;
	c_FlashMiniB3D.m_last_texture=null;
	c_FlashMiniB3D.m_last_sprite=null;
	c_FlashMiniB3D.m_current_cam=null;
	c_FlashMiniB3D.m_alpha_list=(new c_SurfaceAlphaList).m_SurfaceAlphaList_new();
	c_TLight.m_ambient_red=0.1;
	c_TLight.m_ambient_green=0.1;
	c_TLight.m_ambient_blue=0.1;
	c_TexData.m_null_tex=null;
	c_FlashMiniB3D.m_last_tex_count=8;
	c_FlashMiniB3D.m_null_tex=null;
	c_FlashMiniB3D.m_temp_cam=(new c_Matrix).m_Matrix_new();
	c_FlashMiniB3D.m_temp_mat=(new c_Matrix).m_Matrix_new();
	c_Matrix.m_temp=(new c_Matrix).m_Matrix_new();
	c_TRender.m_vbo_enabled=false;
	c_TEntity.m_global_mat=(new c_Matrix).m_Matrix_new();
	c_FlashMiniB3D.m_fastQuad=null;
	c_FlashMiniB3D.m_shader2d_=null;
	c_MojoSurface.m_list=new_string_array(0);
	c_MojoSurface.m_isLoading=false;
	c_TSprite.m_temp_mat=(new c_Matrix).m_Matrix_new();
}
//${TRANSCODE_END}
